hello so i got this sprint script
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local runSpeed = 25
local walkSpeed = 14
local slowDown = 6
local isSprinting = false
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
shiftToSprint()
end
end)
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputEnded:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
shiftToSprint()
end
end)
-- Function to switch between sprinting and walking
function shiftToSprint()
if isSprinting then
-- Set the speed back to the walk speed
humanoid.WalkSpeed = walkSpeed
-- Reset the camera zoom
camera.FieldOfView = 60
isSprinting = false
else
humanoid.WalkSpeed = runSpeed
camera.FieldOfView = 65
isSprinting = true
wait(5)
camera.FieldOfView = 60
humanoid.WalkSpeed = walkSpeed
game.Lighting.ColorCorrection.Contrast = 0.1
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.2
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.3
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.4
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.5
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.6
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.7
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.8
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.9
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 1
humanoid.WalkSpeed = slowDown
script.Enabled = false
camera.FieldOfView = 60
wait(5)
humanoid.WalkSpeed = walkSpeed
script.Enabled = true
game.Lighting.ColorCorrection.Contrast = 1
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.9
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.8
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.7
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.6
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.5
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.4
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.3
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.2
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0.1
wait(.00001)
game.Lighting.ColorCorrection.Contrast = 0
end
end
and how it works is that when i hold sprint it just does all the things and if i keep holding ill slow down and wont be abe to sprint for 5 seconds. But the problem is that when i click shift and just don’t hold it, the script still thinks im holding shift. how do i fix that?
3 Likes
I saw ya typing lol. justkidding
I’ll help in a bit, I’ll get the script more readable and then attempt to help.
are ya done doing what ur doing?
You need to remove the waits, that’s why.
The more organised version:
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local isSprinting = false
local function shiftToSprint()
local walkSpeed = 14
local runSpeed = 25
local slowDown = 6
if not isSprinting then
humanoid.WalkSpeed = walkSpeed
-- Reset the camera zoom
camera.FieldOfView = 60
isSprinting = true
if isSprinting then
humanoid.WalkSpeed = runSpeed
camera.FieldOfView = 65
isSprinting = true
wait(5)
camera.FieldOfView = 60
humanoid.WalkSpeed = walkSpeed
game.Lighting.ColorCorrection.Contrast = 0
while game.Lighting.ColorCorrection.Contrast < 1 do
game.Lighting.ColorCorrection.Contrast += 0.1
wait(0.1)
end
humanoid.WalkSpeed = slowDown
wait(5)
humanoid.WalkSpeed = walkSpeed
while game.Lighting.ColorCorrection.Contrast > 0 do
game.Lighting.ColorCorrection.Contrast -= 0.1
wait(0.1)
end
end
isSprinting = false
end
end
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
shiftToSprint()
end
end)
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputEnded:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
shiftToSprint()
end
end)
you have to check if issprinting is now false for the sprinting script, as otherwise, you’d reset ur fov and walkspeed for once, but the function that was called the first time would still be running and would therefore set it back upto a high number
Alright ima try this script real quick.
I don’t know why but now it doesn’t even work. i don’t get any errors in the ouput, but it just doesn’t make me faster and doesn’t change the fov.
you did the if wrong if I am correct. the first time they press shift rn would result in resetting the camera and not activating the sprint
(move the not from the first if to the second)
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local walkSpeed = 14
local runSpeed = 25
local slowDown = 6
local function Walk()
humanoid.WalkSpeed = walkSpeed
-- Reset the camera zoom
camera.FieldOfView = 60
end
local function Run()
humanoid.WalkSpeed = runSpeed
camera.FieldOfView = 65
wait(1)
camera.FieldOfView = 60
humanoid.WalkSpeed = walkSpeed
game.Lighting.ColorCorrection.Contrast = 0
while game.Lighting.ColorCorrection.Contrast < 1 do
game.Lighting.ColorCorrection.Contrast += 0.1
wait(0.1)
end
humanoid.WalkSpeed = slowDown
wait(5)
humanoid.WalkSpeed = walkSpeed
while game.Lighting.ColorCorrection.Contrast > 0.1 do
game.Lighting.ColorCorrection.Contrast -= 0.1
wait(0.1)
end
end
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
Run()
end
end)
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputEnded:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
Walk()
end
end)
This might’ve been the issue, retry.
Sadly it still doesn’t work. it just doesn’t change the fov or trigger the run function.
That is strange. It does work for me; Insert it into ‘StarterPlayerScripts’.
Oh you put it in StarterPlayer. i had it in starter character. ill try it now!
Alright so the thing is that first. its buggy as hell. and i still have the same problem.
I have just one question.
what
1 Like
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local camera = game.Workspace.CurrentCamera
local walkSpeed = 14
local runSpeed = 25
local slowDown = 6
local Debounce = tick()
local function Walk()
humanoid.WalkSpeed = walkSpeed
-- Reset the camera zoom
camera.FieldOfView = 60
end
local function Run()
Debounce = tick()
humanoid.WalkSpeed = runSpeed
camera.FieldOfView = 65
wait(1)
camera.FieldOfView = 60
humanoid.WalkSpeed = walkSpeed
game.Lighting.ColorCorrection.Contrast = 0
while game.Lighting.ColorCorrection.Contrast < 1 do
game.Lighting.ColorCorrection.Contrast += 0.1
wait(0.1)
end
humanoid.WalkSpeed = slowDown
wait(5)
humanoid.WalkSpeed = walkSpeed
while game.Lighting.ColorCorrection.Contrast > 0.1 do
game.Lighting.ColorCorrection.Contrast -= 0.1
wait(0.1)
end
end
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputBegan:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
if tick() - Debounce < 5 then return end
Run()
end
end)
-- Bind the key "LeftShift" to the function "shiftToSprint"
game:GetService("UserInputService").InputEnded:Connect(function(inputObject)
if inputObject.KeyCode == Enum.KeyCode.LeftShift then
Walk()
end
end)
With debounce, try now. FOV and ColorCorrection work for me. The problem are most likely the waits.
Idk why but im still having the problem. what i mean is that… when i click shift the script thinks im holding shift
here’s the example (btw i used the script u just sent me)
You can see the problem at like 6 or 7 seconds into the video.
As you see i just press shift and i still get slowed down and the contrast goes up.