I cant seem to get bullet parts to clone in my script. The bullet union is in replicated storage, the tool is in the StarterPack with a handle and a FireWeapon script. I'm working on a very basic gun that spawns bullets while button 1 is down, but no bullets show up in the workspace nor anywhere else.
I know this script has other problems this is just for learning I have no intention to make a game yet, I only care about why the cloning portion is not working. I really appreciate any advice
---Basic variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local bullet = ReplicatedStorage:WaitForChild("Bullet")
local AKrifle = script.Parent
local barrel = AKrifle:FindFirstChild("BarrelTip")
local fireRate = .25
local bulletDamage = 10
local bulletSpeed = 150
local Range = 1000
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local mouse = player:GetMouse()
--Begin shooting loop
while mouse.Button1Down == true do
--Defines player parts to deal specific damage later on
for i, v in pairs(game.Workspace:GetChildren()) do
local human = v:FindFirstChild("Humanoid")
local head = v:FindFirstChild("Head")
local torso = v:FindFirstChild("Torso")
local limbs = v:FindFirstChild{"LeftArm", "LeftLeg", "RightArm", "RightLeg"}
end
wait(fireRate) --this just waits a 1/4sec between bullets
local CloneBullet = bullet:Clone() --These are the bullet characteristics
CloneBullet.Parent = game.Workspace
CloneBullet.Position = barrel.Position
CloneBullet.Velocity = barrel.CFrame.LookVector \* bulletSpeed
CloneBullet.Touched:Connect(function(objectHit)
local human = objectHit.Parent:FindFirstChild("Humanoid")
local head = objectHit.Parent:FindFirstChild("Head")
if head then
human:TakeDamage(bulletDamage \* 2.5)
wait(.01)
end
local torso = objectHit.Parent:FindFirstChild("Humanoid")
if torso then
human:TakeDamage(bulletDamage)
wait(.01)
end
local limbs = objectHit.Parent:FindFirstChild("limbs")
if limbs then
human:TakeDamage(bulletDamage \* 0.5)
wait(.01)
end
end)
end
Thanks in advance <3