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

Why does this script work for animations and walk speed?

I have not done a lot of scripting with animations so I just wanted to ask how and why this script works (Pls break down the script) ~~~~~~~~~~~~~~~~~ local UIS = game:GetService('UserInputService') local Player = game.Players.LocalPlayer local Character = Player.Character

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. if input.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.WalkSpeed = 25 local Anim = Instance.new('Animation') Anim.AnimationId = 'rbxassetid://10867310905' PlayAnim = Character.Humanoid:LoadAnimation(Anim) PlayAnim:Play() end end)

UIS.InputEnded:connect(function(input) if input.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.WalkSpeed = 16 PlayAnim:Stop() end end)


2 comments

0

this is a scripting helper page,not "how scripts work" or a scripting tutorial page man

0

We are helping them understand the script Iamgogo... scripting helpers is about helping with anything regarding scripts

1 answer

Alright, so first of all

local UIS = game:GetService('UserInputService') local Player = game.Players.LocalPlayer local Character = Player.Character

UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35. 
	if input.KeyCode == Enum.KeyCode.LeftShift then 
		Character.Humanoid.WalkSpeed = 25 
		local Anim = Instance.new('Animation') 	
		Anim.AnimationId = 'rbxassetid://10867310905' 	
		PlayAnim = Character.Humanoid:LoadAnimation(Anim) 
		PlayAnim:Play() 
	end 
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then 
		Character.Humanoid.WalkSpeed = 16 
		PlayAnim:Stop() 
	end 
end)

I will break it into 2 parts. Explaining inputBegan and inputEnded

Inputbegan registers when they press any key. This script checks if the key they pressed was the Left shift. If it was, then it increases their walkspeed. Then it creates a new animation, sets the ID (the animation it will play) and loads the animation. after loading, it plays.

InputEnded registers when any type of input ends. So the script checks what input ended, which is the leftShift. Then it sets their walkspeed back to normal, and the animation is stopped.

If this answer helped you, then please accept it and upvote it. If you want to talk more about scripting, message me on iNi#2338

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