Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Clickable part to give gun?

Asked by 6 years ago

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)

1
Use a code block next time to display code. hiimgoodpack 2009 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago
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'



0
Didn't appear to work Arkevos 0 — 6y
1
And make sure that your brick had 'ClickDetector' on it User#17685 0 — 6y
0
tab_your_code Goulstem 8144 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

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) :-)

0
oh and also wherever it says Tool, change it to the name of your tool lukebloxdaily 6 — 6y

Answer this question