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

Activated and Deactivated script not working?

Well I’m trying to see if my script works, so that when I click it activates or deactivates but I don’t know what is wrong with my script, anyone could help?

local Tool = script.Parent

Tool.Activated(function()
      print(“I am so happy”)
end)

Tool.Deactivated(function()
      print(“awww man I so sad”)
end)

3 comments

0

Try replacing: Tool.Activated and Tool.Deactivated with Tool.Activated:Connect and Tool.Deactivated:Connect.

0

Ooh it worked, thanks, I would’ve upvoted your but it wasn’t an answer..

0

I'll post it right now.

1 answer

✓ Accepted answer

Just change a few things..

local Tool = script.Parent
	 
	Tool.Activated:Connect(function()
	      print(“I am so happy”)
	end)
	 
	Tool.Deactivated:Connect(function()
	      print(“awww man I so sad”)
	end)

You needed to actually connect the event to the function, hints :Connect. Though I've been testing, and that didn't work for me? But, if you run into any problems, use this, the script that worked for me. (this code is a localscript, child of the tool)

local tool = script.Parent
function check()
	if tool.Parent == game.Players.LocalPlayer.Backpack then
		print("Unequipped!")
	elseif tool.Parent == game.Players.LocalPlayer.Character then
		print("Equipped!")
	end
end
tool.AncestryChanged:Connect(check)

There you go! 2 ways to do it! Good luck on whatever you're doing!

8 comments

0

What does the second script mean, can you go step by step?

0

Alright. When the tool is equipped, the parent of it is the players characters. When the tool is unequipped, the parent of it is the player.Backpack. That is why I'm detecting when the parent is this, therefore detecting when the tool is equipped or unequipped. Any further questions? I'll be happy to answer.

0

Well there was this script I’ve been trying to do for a while but I’ve never knew how.. are you up to the job?

0

And what does function check() on line 2 mean?

0

That is just what I named the function. So when the tool's AncestryChanged (meaning when it's parent changed) it runs the function.

0

Why u put ==

0

== means equal to, you can't just put "=" in this type of code.

0

== means equal to, you can't just put "=" in this type of code.

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