Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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



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)

2 comments

0

Please use code blocks.

0

How

1 answer

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)

1 comment

0

i learned something new today

This discussion is preserved as it was. New answers, comments, and votes are closed.