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

How would I make the animation work for my sprint script?

I have tried to add an animation when sprinting to my script but it doesn't seem to work, the output says: "Stop is not a valid member of animation"

local anim = script.RunAnim
repeat wait() until script.Parent.Name == "Backpack"
script.KeyDown.OnServerEvent:Connect(function(asd,yo)
	if yo == "0" then
		script.Parent.Parent.Character.Humanoid.WalkSpeed = 20
		anim:Play()
	end
end)
script.KeyUp.OnServerEvent:Connect(function(asd,yo)
	if yo == "0" then
		script.Parent.Parent.Character.Humanoid.WalkSpeed = 13
		anim:Stop()
	end
end)

1 answer

✓ Accepted answer

Okay, a lot of mistakes but I'll help you out.

Make a local script (Client script), put inside the animation (named RunAnim),put it in the starter pack and write the following:

local UIS = game:GetService("UserInputService")
local p = game:GetService("Players").LocalPlayer
local c  = p.Character or p.CharacterAdded:Wait()
local anim = script.RunAnim
local RunAnimation = c:WaitForChild("Humanoid"):LoadAnimation(anim)
UIS.InputBegan:Connect(function(i,a)
	if not a then
		if i.KeyCode == Enum.KeyCode.LeftShift then
			c:WaitForChild("Humanoid").WalkSpeed = 20
			RunAnimation:Play()
		end
	end
end)

UIS.InputEnded:Connect(function(i,a)
	if not a then
		if i.KeyCode == Enum.KeyCode.LeftShift then
			c:WaitForChild("Humanoid").WalkSpeed = 13
			RunAnimation:Stop()
		end
	end
end)

1 comment

0

Works thx

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