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)

1 comment
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.