Trying to make so that a part gives a gun when you click on it. Doesn't appear to be working as it either gives me all the guns in lightning or none.
function onClick(click) for i,v in pairs (game.Lighting:GetChildren()) do if v.ClassName == "Tools" then c = v:Clone() c.Parent = click.Backpack end end end script.Parent.ClickDetector.MouseClick:connect(onClick)
function onClick(whoClicked) for i,v in pairs (game.Lighting:GetChildren()) do if v.ClassName == "Tool" and v.Name=="m16" then -- Every children of Lighting that is Class Tool will be copied to your backpack .. Just specify which weapon or Tool (m16) c = v:Clone() c.Parent = whoClicked.Backpack end end end script.Parent.ClickDetector.MouseClick:connect(onClick) --Must be 'ClickDetector'
put this in a localscript into StarterGui
part = Part --name of the part you click game.Workspace.part.ClickDetector.MouseClick:connect(function() --add clickdetector in part game.ReplicatedStorage.Tool:clone() --put the tool you want it to give in replicatedstorage game.ReplicatedStorage.Tool:clone().Parent = game.Players.LocalPlayer.Backpack
hope this works and make sure you follow all the instructions (the green text) :-)