I made this script which detects if a player has an attribute attached to their character that serves as a way to detect which ability they got equipped, and depending on that it changes their animations to custom ones. The issue is, whenever I click play and stop there’s an around 30% chance of the script not working. It only prints “given animation” strangely, and does not replace the animate script at all. How would I go about solving this?
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(char)
local value = char:GetAttribute("CurrentStand")
if value == "exampleability" then
print("nobody knows")
local oldanim = char:WaitForChild("Animate")
oldanim:Destroy()
--
local newanim = script.Animate:Clone()
newanim.Parent = char
newanim.Disabled = false
end
print("given animation")
end)
end)
Edit: For context, I got another script that adds the attribute to the desired value on player entered. I don’t understand how it sometimes works and sometimes this script skips the attribute check, the first print, and doesn’t give the animations but somehow still prints the last print