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

Hi! Im trying to make a sprint script there players need to press Shift to sprint?

My script doesnt work. Ive been trying to make a script for the players to press shift if they want to run faster! But it doesnt work. Have I made a mistake in the script or what is it?

3 comments

0

local Player = game.Players.LocalPlayer local Character = Player.Character local Camera = game.Workspace.CurrentCamera local SpeedBoost = 35 local DefaultSpeed = 16 local UserInputService = game:GetService("UserInputService") UserInputService.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then Character.Humanoid.Walkspeed = SpeedBoost Camera.FieldOfView = Camera.Fie

0

Can you please Edit your post so you can put the script inside a Code Block. It's really hard to read it like that.

0

Show the script, please?

2 answers

✓ Accepted answer

Something like this would work, but you should re-edit your question and give code.

--in a local script
--in startercharacterscripts
local userInputService = game:GetService("UserInputService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
--get the speeds
loca RUNSPEED = 25
local DEFAULTSPEED = humanoid.WalkSpeed

--if they press shift
userInputService.InputBegan:Connect(function(keyPressed)
	if keyPressd.KeyCode = Enum.KeyCode.LeftShift then
		humanoid.WalkSpeed =  RUNSPEED
	end
end)

--when they let go of shift
userInputService.InputEnded:Connect(function(keyPressed)
	if keyPressed.KeyCode = Enum.KeyCode.LeftShift then
		humanoid.WalkSpeed = DEFAULTSPEED
	end
end)

1 comment

0

Hey in your code you said loca instead of local!

So it seems you want to make a sprinting script ey? well I'll help you out. P.S. Im not too sure on how to make it work when you hold it down, So im doing my best.

now First you create two local scripts and put them into StarterPlayer>StarterCharacterScripts.

Now, Name the first one anything you like and name the second one anything too. (But I don't recommend putting spaces in the Name)

Now you put the second script onto the First one making the Second local script the child of the first one.

This is the First Scripts code.

local UIS = game:GetService("UserInputService")
local WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
local SecondScript = script.(Second Script Name)

UIS.InputBegan:Connect(function(input)
	local Pressed = input.KeyCode
	if Pressed == Enum.KeyCode.LeftShift then
		WalkSpeed = 30 --Add any number on what speed you want.
		script.Disabled = true
		SecondScript.Disabled = false
	end
end)

And this one is the Second script code.

local UIS = game:GetService("UserInputService")
local WalkSpeed = game.Players.LocalPlayer.Character.Humanoid.WalkSpeed
local FirstScript = script.Parent

UIS.InputBegan:Connect(function(input)
	local Pressed = input.KeyCode
	if Pressed == Enum.KeyCode.LeftShift then
		WalkSpeed = 30 --Speed number thing.
		script.Disabled = true
		FirstScript.Disabled = false
	end
end)

You can just copy and paste the scripts above.

Hope that this works for you. Toodles.

(They have to be LocalScripts and/or in StarterPlayer>StarterCharacterScripts, else this would not work)

3 comments

0

Why do you need 2 Scripts?

0

And you are supposed to be explaining why her script isn't working, not giving her a whole different script.

0

Oh heck, well I mean this works too.

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