Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LoadAnimation requires the Humanoid object to be a descendant of the game object?

Asked by 6 years ago
Edited 6 years ago


local CAS = game:GetService("ContextActionService") local UIS = game:GetService("UserInputService") local jumpDisabled = false local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:wait() local hum = char:WaitForChild("Humanoid") local run_Anim = hum:LoadAnimation(script:WaitForChild("ExportAnim")) function onJump() if jumpDisabled then hum.Jump = false end end function toggleSprint(actionName, inputState, inputObject) if inputState == Enum.UserInputState.Begin then hum:LoadAnimation(script:WaitForChild("ExportAnim")):Play() hum.WalkSpeed = 35 jumpDisabled = true elseif inputState == Enum.UserInputState.End then hum:LoadAnimation(script:WaitForChild("ExportAnim")):Stop() hum.WalkSpeed = 16 jumpDisabled = false hum:LoadAnimation(script:WaitForChild("WalkAnim")):Play() end end function windowFocused() hum:LoadAnimation(script:WaitForChild("ExportAnim")):Stop() hum.WalkSpeed = 16 jumpDisabled = false end CAS:BindAction("toggleSprint", toggleSprint, false, Enum.KeyCode.LeftShift) UIS.WindowFocused:connect(windowFocused) hum.Changed:connect(onJump)
0
Please use code blocks. User#19524 175 — 6y
0
How Jade7070 0 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

If the the character resets, its parent is set to nil. You should set the char variable to the new character everytime that happens.

player.CharacterAdded:Connect(function(character)
    char = character
end)

0
i learned something new today User#19524 175 — 6y
Ad

Answer this question