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?

4 comments
What is the local real = false??
Why are all your variables inside the Tool.Equipped Connection?
That was the issue, the entire script was inside the .Equipped function
Im not sure what that means but real = false at the start because by default real would equal true, and the player would be able to play the animation while the tool was unequipped but not while it was equipped