I have this script which detects if the player got “Infected” and when I try loading the animation it comes up with a error.
The error says that its unable to cast value to object at the load animation part.
I have this script which detects if the player got “Infected” and when I try loading the animation it comes up with a error.
The error says that its unable to cast value to object at the load animation part.
while task.wait() do
if Player.Team == game.Teams.Infected then
if Team_Player == true then
Humanoid.Animator:LoadAnimation(InfectAnim):Play()
Humanoid.JumpPower = 0
Humanoid.WalkSpeed = 0
Humanoid.AutoRotate = false
script.Parent.Animate.idle.Animation1.AnimationId = “rbxassetid://8177163203”
script.Parent.Animate.idle.Animation2.AnimationId = “rbxassetid://8177163203”
script.Parent.Animate.run.RunAnim.AnimationId = “rbxassetid://8177414818”
script.Parent.Animate.walk.WalkAnim.AnimationId = “rbxassetid://8177414818”
Team_Player = false
task.wait(7)
Humanoid.JumpPower = 60
Humanoid.WalkSpeed = 10
Humanoid.AutoRotate = true
end
humanoid:LoadAnimation() is deprecated. Do humanoid.Animator:LoadAnimation() instead.
Make sure “InfectAnim” is actually an animation
Btw I highly recommend doing GetPropertyChangedSignal
and to detect whenever the player team changes, instead of doing while wait() do
Blockquote
Oh forgot to show the variable.
local InfectAnim = “rbxassetid://8177592593”
I don’t really know how to loop so ill try that out. But how do I use it?
Player:GetPropertyChangedSignal("Team"):Connect(function())
--code here
end)
Do I do Player.Team.ChangedPropertySignal:Connect(function()
Oh thank you, I didn’t find the issue but I found a solution that I hate, using 2 scripts on the infect part.
I used a local script in startercharacterscripts I think that might be the issue? Im not sure.
local InfectAnim = “rbxassetid://8177592593”
Player:GetPropertyChangedSignal("Team"):Connect(function())
if Player.Team == "Infected" then
local newAnim = Instance.new("Animation")
newAnim.AnimationId = InfectAnim
Humanoid.Animator:LoadAnimation(newAnim):Play()
end
end)
Alright I’ll try that instead.
Thank you! I am thankful for your help! Thanks for telling me how to use GetPropertyChangedSignal Im pretty sure it will cause less lag as well.