I am making a gun spawner thing for my game of course, but the gun won't spawn. No errors, the printing works perfeclty fine at the top, but when it gets to the gun spawning, it breaks. Please help;
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
script.Parent.ClickDetector.MaxActivationDistance = 0
print(plr.Name)
-- varibles
local bar = script.Parent.Parent.barrier
local num = math.random(1,4)
script.Parent.Parent.machinegiv.Value = num -- telling the random number to be in the vale of the into int value in the model
wait(.01)
bar.one.CanCollide = true
bar.two.CanCollide = true
bar.three.CanCollide = true
bar.four.CanCollide = true
--buying
print(plr.leaderstats.Money.Value)
if plr.leaderstats.Money.Value < 5000 then
script.Parent.Parent.sensor.BrickColor = BrickColor.Red()
wait(2)
script.Parent.Parent.sensor.BrickColor = BrickColor.White()
script.Parent.ClickDetector.MaxActivationDistance = 32
bar.one.CanCollide = false
bar.two.CanCollide = false
bar.three.CanCollide = false
bar.four.CanCollide = false
elseif
plr.leaderstats.Money.Value > 5000 then
script.Parent.Parent.sensor.BrickColor = BrickColor.Green()
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - 5000
wait(.5)
if script.Parent.Parent.machinegiv.Value == 1 then
local clone = game.ServerStorage.guns.Pistol:Clone()
clone.Parent = game.Workspace
elseif
script.Parent.Parent.machinegiv.Value == 2 then
local clone = game.ServerStorage.guns.SMG:Clone()
clone.Parent = game.Workspace
elseif
script.Parent.Parent.machinegiv.Value == 3 then
local clone = game.ServerStorage.guns.AR:Clone()
clone.Parent = game.Workspace
elseif
script.Parent.Parent.machinegiv.Value == 4 then
local clone = game.ServerStorage.guns.Shotgun:Clone()
clone.Parent = game.Workspace
end
wait(4)
script.Parent.Parent.sensor.BrickColor = BrickColor.White()
script.Parent.ClickDetector.MaxActivationDistance = 32
bar.one.CanCollide = false
bar.two.CanCollide = false
bar.three.CanCollide = false
bar.four.CanCollide = false
end
end)
When it gets to about this it breaks
wait(.5)
if script.Parent.Parent.machinegiv.Value == 1 then
local clone = game.ServerStorage.guns.Pistol:Clone()
clone.Parent = game.Workspace
elseif -- and it goes on ;)
No errors, like I said the prints work fine at the top.

3 comments
is this a server script or a local script
server
Do the guns show in the explorer when they are spawned? They could be spawned in an unexpected position or possibly fall through the map if they have collisions off