#The sprinting script wont work in my game!

1 messages · Page 1 of 1 (latest)

tranquil meadow
#

So i made a local script for the sprinting walk shift but it did not work i put them in the right places, why is it not working?

tranquil meadow
tranquil meadow
# finite pebble

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local walkSpeed = 16
local sprintSpeed = 20

player.CharacterAdded:Connect(function(char)
character = char
humanoid = character:WaitForChild("Humanoid")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
if humanoid then
humanoid.WalkSpeed = sprintSpeed
end
end
end)

UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid then
humanoid.WalkSpeed = walkSpeed
end
end
end)

RunService.RenderStepped:Connect(function()
if UserInputService.TouchEnabled then
if humanoid and humanoid.MoveDirection.Magnitude > 0 then
humanoid.WalkSpeed = sprintSpeed
else
humanoid.WalkSpeed = walkSpeed
end
end
end)

#

i put that in starter player scripts

#

local script

#

didnt work

karmic crypt
#
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local walkSpeed = 16
local sprintSpeed = 20

player.CharacterAdded:Connect(function(char)
    character = char
    humanoid = character:WaitForChild("Humanoid")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
        if humanoid then
            humanoid.WalkSpeed = sprintSpeed
        end
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        if humanoid then
            humanoid.WalkSpeed = walkSpeed
        end
    end
end)

RunService.RenderStepped:Connect(function()
    if UserInputService.TouchEnabled then
        if humanoid and humanoid.MoveDirection.Magnitude > 0 then
            humanoid.WalkSpeed = sprintSpeed
        else
            humanoid.WalkSpeed = walkSpeed
        end
    end
end)
finite pebble
#

seems to be working just fine. But you do have a rather low difference between sprinting and walking, so it is almost not noticeable

tranquil meadow
#

we need players to sprint fast!

finite pebble
#

Well then... actually increase the difference

#

16 -> 20 is a barely noticeable increase

tranquil meadow
tranquil meadow
#

thats why it didnt got noticed

#

gosh dang it am such an idiot

#

is my script a fully working script or does it have some errors

finite pebble
#

Well the renderstepped function seems a bit off, as it doesn't really do anything currently

tranquil meadow
finite pebble
#

I mean, you can just remove that last function

#

But the rest of the script is working just fine

oblique glenBOT
#

studio** You are now Level 1! **studio

finite pebble
#

That's your script just posted in a codeblock

tranquil meadow
#

how do i do that

#

the run service?

#

do i delete that

finite pebble
#

Please learn the absolute basics of using a computer...

finite pebble
#

Just remove that last function, then change the number after sprintSpeed

tranquil meadow
#

got it

#

thank you

#

complete

#

thanks

tranquil meadow
finite pebble
#

They should add a mandatory IQ test for folks wishing to access the internet

finite pebble
#
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local walkSpeed = 16
local sprintSpeed = 20 -- increase this number to your liking

player.CharacterAdded:Connect(function(char)
    character = char
    humanoid = character:WaitForChild("Humanoid")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
        if humanoid then
            humanoid.WalkSpeed = sprintSpeed
        end
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        if humanoid then
            humanoid.WalkSpeed = walkSpeed
        end
    end
end)
tranquil meadow
#

this is the result local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local walkSpeed = 16
local sprintSpeed = 30

player.CharacterAdded:Connect(function(char)
character = char
humanoid = character:WaitForChild("Humanoid")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
if humanoid then
humanoid.WalkSpeed = sprintSpeed
end
end
end)

UserInputService.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
if humanoid then
humanoid.WalkSpeed = walkSpeed
end
end
end)

#

but it yet did not wor

finite pebble
#

... Is it a local script?

tranquil meadow
finite pebble
#

What is the script's parent?

tranquil meadow
#

in starter player scripts

wintry moat
tranquil meadow
finite pebble
#

It works just fine

#

You are actually holding down the left shift button right?

tranquil meadow
#

am doing it in test play

finite pebble
#

And you are noticing the mild speed increase, right?

finite pebble
#
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local walkSpeed = 16
local sprintSpeed = 300

player.CharacterAdded:Connect(function(char)
    character = char
    humanoid = character:WaitForChild("Humanoid")
end)

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.LeftShift and not gameProcessed then
        if humanoid then
            humanoid.WalkSpeed = sprintSpeed
        end
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift then
        if humanoid then
            humanoid.WalkSpeed = walkSpeed
        end
    end
end)

if UserInputService.TouchEnabled then
    humanoid.WalkSpeed = sprintSpeed
end

use this

#

Then tell me if you can notice it

#

Bottom was just quickly added for those mobile players

finite pebble
#

Press ctrl + shift + F. Then in the window that opens up type "Walkspeed", then tell me how many results that is showing

#

as seen in this image

finite pebble
#

In the window that opens up after pressing down those 3 buttons

oblique glenBOT
#

studio** You are now Level 2! **studio

tranquil meadow
#

it shows many stuff

finite pebble
#

How many results?

#

Says it right underneath the search bar

tranquil meadow
#

in 10 files

finite pebble
#

So you've 10 scripts all trying to change the walkspeed

#

this is why you don't use AI for coding

#

Welp, have fun fixing it

tranquil meadow
#

@finite pebble

finite pebble
#

Eh fuck it, let me explain it in simple terms.

Say 5 people are sitting in a room, all wanting the room to be a different temperature. Everybody is messing with the thermostat and causing the room to constantly change temperatures, what you just did is add another person onto that pile and asked him to set the temperature to 35 C, and now you're confused that it's not reaching 35 C, as somebody else keeps changing it back.

Now your AI scripts are doing the same

#

This is why you learn how to code

#

So have fun fixing that with chatgpt or whatever, as I highly doubt that anybody is going to helop you fix that mess

tranquil meadow
tranquil meadow
#

those have nothing to do with sprints

#

using Lshift

finite pebble
#

Yet they still try to change your walkspeed back

#

This is why you learn how to script, instead of just pasting in modules, ai code, etc. then complain that shit isn't working

tranquil meadow
#

shit