Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Clickable part to give gun?

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 comment

1

Use a code block next time to display code.

2 answers

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'



3 comments

0

Didn't appear to work

1

And make sure that your brick had 'ClickDetector' on it

0

tab_your_code

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

1 comment

0

oh and also wherever it says Tool, change it to the name of your tool

This discussion is preserved as it was. New answers, comments, and votes are closed.