I only want to player to play an animation when a tool in the backpack is equipped, but the animation does not play even when the tool is equipped. The script knows the tool is equipped as it prints true and false, but the animation still does not play. Code here:
local real = false script.Parent.Equipped:Connect(function() local real = true print(real) script.Parent.Unequipped:Connect(function() local real = false print(real) local LocalPlayer = game:GetService("Players").LocalPlayer local Controls = require(LocalPlayer.PlayerScripts.PlayerModule):GetControls() local UIS = game:GetService("UserInputService") local character = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name) local boom = character:WaitForChild("Humanoid") :LoadAnimation(script:WaitForChild("boom")) UIS.InputBegan:Connect(function(key,chat) if chat then return end if real == false then return end if key.KeyCode == Enum.KeyCode.E then boom:play() Controls:Enable(false) wait(2) Controls:Enable(true) end end) end) end)
How should I fix it?
I rewrote your script to make it more organized... Don't put your variables inside connections unless you need to rewrite them
It should work now, if it doesn't that means that the animation has no ID
--VARIABLES-- local LocalPlayer = game:GetService("Players").LocalPlayer local Controls = require(LocalPlayer.PlayerScripts.PlayerModule):GetControls() local UIS = game:GetService("UserInputService") local character = game.Workspace:WaitForChild(game.Players.LocalPlayer.Name) local boom = character:WaitForChild("Humanoid") :LoadAnimation(script:WaitForChild("boom")) local real = false --CONNECTIONS-- script.Parent.Equipped:Connect(function() local real = true print(real) end) script.Parent.Unequipped:Connect(function() local real = false print(real) end) UIS.InputBegan:Connect(function(key,chat) if chat then return end if real == false then return end if key.KeyCode == Enum.KeyCode.E then boom:play() Controls:Enable(false) wait(2) Controls:Enable(true) end end)
Ok, so. This might not be the problem, but this is what might be causing it.
Tools that have it enabled to require a handle (Enabled by default.) without a part in it called 'Handle' will NOT fire a .Equipped or .Unequipped function.