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)
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)