How do i make toggle sprint script with R6 animation

I was trying to make a toggle sprint with animation but i failed each time. I dont know what to do

There weren’t any videos about toggle sprint with animation im stuck with that.

Here is a snippet with custom locations.

local Character:Model? = script.Parent
local Humanoid:Humanoid? = Character:WaitForChild("Humanoid")
local Animator:Animator? = Humanoid:WaitForChild("Animator")
local SprintAnimation = Animator:LoadAnimation(game:GetService("ReplicatedStorage").Storage.Animations.Sprint) -- Change
local IsSprinting:BoolValue? = script.Sprinting -- Make a boolvalue inside character or script.
local UIS = game:GetService("UserInputService")
Humanoid.Changed:Connect(function(Prop)
	if Prop == "MoveDirection" then
		if Humanoid.MoveDirection.Magnitude <= 0 then
			SprintAnimation:Stop()
		end
	end
end)
Humanoid.Running:Connect(function()
	if IsSprinting.Value == true then
		SprintAnimation:Play()
	else
		SprintAnimation:Stop()
	end
end)
IsSprinting.Changed:Connect(function(Value)
	if Value then
		Humanoid.WalkSpeed = 24
	else
		Humanoid.WalkSpeed = 16
	end
end)
UIS.InputBegan:Connect(function(Input,GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.E then
		IsSprinting.Value = not IsSprinting.Value
	end
end)
4 Likes

thank you very much i was suffering for 3 hours thank you i just need 30 words

It’s fine, if my snippet helped, you can mark it as a solution to close this thread.

1 Like

Uhm i dont understand where do i place the ID of the animation?

Make a new animation object and change its id. you can replcae it anywhere and change the script location in here.
local SprintAnimation = Animator:LoadAnimation(somewhere where it is) -- Change

1 Like

Uhm sorry for disturbing alot but i dont know what Animation object i didn’t learn lua but i’m trying to learn
it’s my first time trying to make a game so im trying my best. I watch tutorials but they are confusing i dont read anything.

there i can do it for you.

local Character:Model? = script.Parent
local Humanoid:Humanoid? = Character:WaitForChild("Humanoid")
local Animator:Animator? = Humanoid:WaitForChild("Animator")
local ID = id
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..ID
Animation.Parent = script
local SprintAnimation = Animator:LoadAnimation(Animation) -- Change
local IsSprinting:BoolValue? = script.Sprinting -- Make a boolvalue inside character or script.
local UIS = game:GetService("UserInputService")
Humanoid.Changed:Connect(function(Prop)
	if Prop == "MoveDirection" then
		if Humanoid.MoveDirection.Magnitude <= 0 then
			SprintAnimation:Stop()
		end
	end
end)
Humanoid.Running:Connect(function()
	if IsSprinting.Value == true then
		SprintAnimation:Play()
	else
		SprintAnimation:Stop()
	end
end)
IsSprinting.Changed:Connect(function(Value)
	if Value then
		Humanoid.WalkSpeed = 24
	else
		Humanoid.WalkSpeed = 16
	end
end)
UIS.InputBegan:Connect(function(Input,GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.E then
		IsSprinting.Value = not IsSprinting.Value
	end
end)
1 Like

thanks i was afk the whole time doing models thanks

1 Like

I did it in startercharacterscripts is it it? bruh i didnt reply but edit devforum is confusing

have you made an boolvalue inside the script named “Sprinting”? also make sure the script is a localscript inside startercharacter;

1 Like

I dont even know what is a boolvalue even though i saw it in youtube

just realized it’s a script to post this comment i have to have wrote in 30 words more so i wrote in these usless ones

i give up i dont even know how to do this and what is boolvalue and where am i supposed to write that in bruh i give up i will never make a game unless i learn lua

local Character:Model? = script.Parent
local Humanoid:Humanoid? = Character:WaitForChild("Humanoid")
local Animator:Animator? = Humanoid:WaitForChild("Animator")
local ID = id
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"..ID
Animation.Parent = script
local SprintAnimation = Animator:LoadAnimation(Animation) -- Change
local IsSprinting = Instance.new("BoolValue")
IsSprinting.Name = "Sprinting"
IsSprinting.Parent = script
local UIS = game:GetService("UserInputService")
Humanoid.Changed:Connect(function(Prop)
	if Prop == "MoveDirection" then
		if Humanoid.MoveDirection.Magnitude <= 0 then
			SprintAnimation:Stop()
		end
	end
end)
Humanoid.Running:Connect(function()
	if IsSprinting.Value == true then
		SprintAnimation:Play()
	else
		SprintAnimation:Stop()
	end
end)
IsSprinting.Changed:Connect(function(Value)
	if Value then
		Humanoid.WalkSpeed = 24
	else
		Humanoid.WalkSpeed = 16
	end
end)
UIS.InputBegan:Connect(function(Input,GPE)
	if GPE then return end
	if Input.KeyCode == Enum.KeyCode.E then
		IsSprinting.Value = not IsSprinting.Value
	end
end)
1 Like

Thank you i know im dumb sorry for disturbing

1 Like

I’m so dumb i dont even understand what to do now it still doesn’t work dont give me any more scripts i give up i will just learn lua i wont ask anymore just for the same thing to happen :skull::skull::skull: But i will still try to find out what am i supposed to do in this part (Animation) --change

just replace “id” with ur animation id

local ID = HERE!!!!!

why didn’t you tell me that before?:skull::skull::skull:

idk if animation works because i couldn’t sprint:|