Im trying to make a animation script that has a state string that will be changed whenever the humanoid state changes, but it always prints out what it currently was and Is never changed.
There’s no errors eathier.
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local idleAnim = Instance.new("Animation")
idleAnim.AnimationId = "rbxassetid://8425357501"
local idleAnimTrack = humanoid:LoadAnimation(idleAnim)
local runAnim = Instance.new("Animation")
runAnim.AnimationId = "rbxassetid://10109174246"
local runAnimTrack = humanoid:LoadAnimation(runAnim)
local rollAnim = Instance.new("Animation")
runAnim.AnimationId = "rbxassetid://10109304466"
local rollAnimTrack = humanoid:LoadAnimation(runAnim)
local jumpAnim = Instance.new("Animation")
jumpAnim.AnimationId = "rbxassetid://10118425407"
local jumpAnimTrack = humanoid:LoadAnimation(jumpAnim)
local JumpSound = Instance.new("Sound")
JumpSound.SoundId = "rbxassetid://8396408200"
JumpSound.Volume = 2.7
JumpSound.Parent = humanoid.Parent:WaitForChild("Torso")
local humanoidStates = {
"Running",
"Jumping",
"FreeFall",
"Swimming",
"Landed",
"Climbing",
"Idle"
}
local state = ""
local UIS = game:GetService("UserInputService")
idleAnimTrack:Play()
while true do
task.wait()
print(state)
if state == "Running" then
runAnimTrack:Play()
idleAnimTrack:Stop()
jumpAnimTrack:Stop()
else
if state == "Jumping" then
jumpAnimTrack:Play()
runAnimTrack:Stop()
idleAnimTrack:Stop()
else
if state == "FreeFall" then
-- Play Free fall
else
if state == "Swimming" then
-- Play Swimg
else
if state == "Landed" then
idleAnimTrack:Play()
runAnimTrack:Stop()
jumpAnimTrack:Stop()
else
if state == "Climbing" then
-- Playing Climbing Animation
else
if state == "Idle" then
idleAnimTrack:Play()
runAnimTrack:Stop()
jumpAnimTrack:Stop()
end
end
end
end
end
end
end
end
UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed and input == Enum.KeyCode.E then
local RollBoost = Instance.new("LinearVelocity")
RollBoost.MaxForce = 99999999999
local Attatchment = Instance.new("Attachment")
RollBoost.Attachment1 = Attatchment
RollBoost.Attachment0 = Attatchment
Attatchment.Parent = script.Parent:WaitForChild("HumanoidRootPart")
end
end)
humanoid.Running:Connect(function(speed)
if speed > 0 then
state = tostring(humanoidStates[1])
else
if speed == 0 then
state = tostring(humanoidStates[7])
end
end
end)
humanoid.Jumping:Connect(function()
state = tostring(humanoidStates[2])
end)
humanoid.FreeFalling:Connect(function()
state = tostring(humanoidStates[3])
end)
humanoid.Swimming:Connect(function()
state = tostring(humanoidStates[4])
end)
if humanoidStates.Landed then
state = tostring(humanoidStates[5])
end
humanoid.Climbing:Connect(function()
state = tostring(humanoidStates[6])
end)