Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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?

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 DogPower05 0 — 4y
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. MRbraveDragon 374 — 4y
0
Show the script, please? Psudar 882 — 4y

2 answers

Log in to vote
0
Answered by
Psudar 882 Moderation Voter
4 years ago
Edited 4 years ago

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)
0
Hey in your code you said loca instead of local! PrismaticFruits 842 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

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)

0
Why do you need 2 Scripts? MRbraveDragon 374 — 4y
0
And you are supposed to be explaining why her script isn't working, not giving her a whole different script. MRbraveDragon 374 — 4y
0
Oh heck, well I mean this works too. roblox136393 32 — 4y

Answer this question