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

Help to make a tool execute an script anyone can help me?

Hello! I'm new to the "Tools" category I was wondering how do I do when I click on my tool to run a script

local lighting = game.Lighting:GetChildren()
local randy = lighting[math.random(1, #lighting)]
randy:Clone().Parent = game.Players.Player1.Backpack

2 answers

✓ Accepted answer

I think I catch your drift on what you're trying to do. Try to post a bit more content on what you want done though, because I only have a vague idea.

So I'm assuming the variable randy is a tool, so to run a script when this item is equipped, you want to do something along these lines with the Equipped event:

randy.Equipped:connect(function(mouse)
	-- code
end)

You can place all the code you want in between randy.Equipped:connect(function(mouse) and end) where the comment is.

__

On the contrary, if you want to have code execute when your tool is deselected/unequipped, you can use the event Unequipped:

randy.Unequipped:connect(function()
	-- code
end)

Once again you can place all the code you want in between randy.Unequipped:connect(function(mouse) and end) where the comment is.

__

Hope this helps! If you have any questions, feel free to leave a comment on my answer.

2 comments

0

randy is random, my script give a random tool from lightning

0

I do not understand much about tools, I thought this would run this script would give a random item to the player who used it

for randy, you can do

randyA = randy:Clone()
randyA.Parent = game.Players.LocalPlayer.Backpack

it has to be in a localscript though.

1 comment

0

This should be a comment, not an answer.

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