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

Activated and Deactivated script not working?

Asked by
iivSnooxy 248 Moderation Voter
3 years ago

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)
0
Try replacing: Tool.Activated and Tool.Deactivated with Tool.Activated:Connect and Tool.Deactivated:Connect. Aztralzz 169 — 3y
0
Ooh it worked, thanks, I would’ve upvoted your but it wasn’t an answer.. iivSnooxy 248 — 3y
0
I'll post it right now. Aztralzz 169 — 3y

1 answer

Log in to vote
1
Answered by
Aztralzz 169
3 years ago
Edited 3 years ago

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!

0
What does the second script mean, can you go step by step? iivSnooxy 248 — 3y
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. Aztralzz 169 — 3y
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? iivSnooxy 248 — 3y
0
And what does function check() on line 2 mean? iivSnooxy 248 — 3y
View all comments (4 more)
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. Aztralzz 169 — 3y
0
Why u put == iivSnooxy 248 — 3y
0
== means equal to, you can't just put "=" in this type of code. Aztralzz 169 — 3y
0
== means equal to, you can't just put "=" in this type of code. Aztralzz 169 — 3y
Ad

Answer this question