Hi, what I'm trying to do here is clone a weapon called "M16" to a players backpack. To do this, I try to cilck a Part and then it will clone a Weapon to a players backpack.
gunmodel = script.Parent
players = game.Players.LocalPlayer
function onClicked()
for i = 1, #players do
if gunmodel ~= nil then
gun = game.Lighting.Weapons.M16:clone()
gun.Parent = players.Backpack
wait(.1)
script.Parent:Destroy()
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

11 comments
Oh yeah, just another tip.. you don't need to use lighting anymore. You can use ServerStorage. It's a better place to store it.
There is a problem. It says that "player" is a nil value
is this a script inside a brick or a player?
It is inside a brick named "Part"
So, do you want to give everyone the gun when the brick is clicked? or just the player who clicked it?
Very sorry for the late reply, I'm trying to give it to the player who clicked it, not everyone.
there, i fixed it for you. it should work fine now
Okay, I'll check it out and give you a green check mark
if it doesn't work, just tell me where it breaks. I might have got the player situation wrong.
Wow, it works, thanks for sticking with me to the end.
Okay, I'll check it out and give you a green check mark