Hello! Can anyone give me a hand, why does activated and deactivated not work? The prints don’t work, it doesn’t fit into that part of the code, what’s wrong?
localscript in StarterCharacterScripts:
-- This code will listen for when the player picks up an ElectricGuitar
-- from their backpack and prints out whether it is activated or deactivated.
local player = game.Players.LocalPlayer
local backpack = player.Backpack
local toolName = "ElectricGuitar"
-- This function will be called whenever a new child is added to the backpack.
-- We use it to check if the child is the ElectricGuitar and if it is a tool.
backpack.ChildAdded:Connect(function(child)
if child.Name == toolName and child:IsA("Tool") then
-- The child is the ElectricGuitar, so we assign it to a variable.
local tool = child
-- This function will be called whenever the ElectricGuitar is activated.
tool.Activated:Connect(function()
-- Print a message to the console.
print("The tool has been activated!")
-- Print whether the tool is currently activated.
print("The tool is currently activated: " .. tostring(tool.Activated))
end)
-- This function will be called whenever the ElectricGuitar is deactivated.
tool.Deactivated:Connect(function()
-- Print a message to the console.
print("The tool has been deactivated!")
-- Print whether the tool is currently deactivated.
print("The tool is currently deactivated: " .. tostring(tool.Activated))
end)
-- Print whether the tool is currently activated.
print("The tool is currently activated: " .. tostring(tool.Activated))
end
end)