I’m making it so when a player has below 30 health an animation plays but its not working my output says
I got an animation in rep storage
Unable to cast value to Object
Script:
local humanoid = character:FindFirstChild("Humanoid")
local animationId = "9738175727"
local loadedAnimation = humanoid:LoadAnimation(animationId)
while wait() do
if humanoid.Health <= 30 then
loadedAnamation:Play()
else
loadedAnimation:stop()
end
end
local Humanoid = character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://9738175727"
local loadedAnimation = Animator:LoadAnimation(Animation)
Humanoid.HealthChanged:Connect(function(Health)
if Health <= 30 then
loadedAnamation:Play()
else
loadedAnimation:stop()
end
end)
Put that inside localscript in startergui or where it was
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://9738175727"
local loadedAnimation = Animator:LoadAnimation(Animation)
Humanoid.HealthChanged:Connect(function(Health)
if Health <= 30 then
loadedAnamation:Play()
else
loadedAnimation:stop()
end
end)