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

Scripting Question on how to script humanoid is in motion or touching the ground?

My problem is that I have implemented a sprint script with an animation on it as well. However, my sprint animation continues even if I were to click another key for another animation to start.

I want to really know how I can write my keybind animation scripts so that they stop when I press another key with another animation so that ,that animation can start.. Also I want to know how to write a script that confirms that the humanoid is touching the ground and that they are in motion.

Please help and thank you!

Here is the code for my sprint animation. It is a remote event.

StarterPlayerScripts

local uis = game:GetService("UserInputService")

local toggleSprintEvent = game.ReplicatedStorage:WaitForChild("ToggleSprint")

uis.InputBegan:Connect(function(key, processed)
	if processed then return end
	
	if key.KeyCode == Enum.KeyCode.LeftControl then
		
		toggleSprintEvent:FireServer(true)
	end
end)


uis.InputEnded:Connect(function(key, processed)
	if processed then return end
	
	if key.KeyCode == Enum.KeyCode.LeftControl then
		
		toggleSprintEvent:FireServer(false)
		
	end
end)

ScriptServerService

local toggleSprintEvent = game.ReplicatedStorage:WaitForChild("ToggleSprint")

toggleSprintEvent.OnServerEvent:Connect(function(player, turnOnSprint)
	local char = player.Character
	local hum = char.Humanoid
	if not char:FindFirstChild("Humanoid") then return end
	
	if turnOnSprint == true then
		
		char:FindFirstChild("Humanoid").WalkSpeed = 50
		  local sprintAnim = Instance.new("Animation")
		
		   sprintAnim.AnimationId = 'rbxassetid://5150687024'
		
		  playAnim = char.Humanoid:LoadAnimation(sprintAnim)
		playAnim:Play()
	else
		char:FindFirstChild("Humanoid").WalkSpeed = 16
		playAnim:Stop()

	end
end)

2 answers

✓ Accepted answer

This answer is just an idea, maybe could make an another button to stop the animation (what I mean is e.g if button 2 (number 2) then stop all animation. I'm just saying.

1 comment

0

Well I took what you said and implemented it into my if statement as an "or" condition and now it does that. Thanks man seriously lol.

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