Changing Player's Speed after it passes limit

Hello, I am doing a simulator game where during the game you can obtain speed through time, but I want there to be a limit on the speed of every player.

It will still go through the limit, and there aren’t errors in the Developer Console.

I’ve been searching a script like this or how to find a player’s humanoid through a server-script to detect it. This is my script:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
        if Character.Humanoid.WalkSpeed >= 101
then
	Character.Humanoid.WalkSpeed = 100
end
	end)
end)
1 Like

Do WaitForChild(“Humanoid”), that’s probably why, you can usee Humanoid.Running and checking speed

1 Like

Doesn’t that only check when the player joins?
You want a script that keeps running during the game. I’d look into your script that changes the speed and put the change limit there.

Yeah, but I am new scripting, what line should I place it at?

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
Character = player.Character or Player.CharacterAdded:Wait()
Character:WaitForChild("Humanoid").Running:Connect(function()
    if Character.Humanoid.WalkSpeed >= 101
then
	Character.Humanoid.WalkSpeed = 100
end
end)
   
	end)
end)

It still wont work. (30 chars)

1 Like

uhm… it should… make sure to change speed from server side not clientisde

1 Like

Why can’t you just check what their current speed is before you give them the speed, instead of changing it afterwards?

You are right. When the speed increased it gave them the speed and after 1 second they had 100 speed, I tried doing that or running the script earlier.

You could do something like this:

local MaxSpeed = 100
local CurrentSpeed = 16 -- 16 is default

while wait(5) do
	if CurrentSpeed == MaxSpeed then
		return
	end
	
	CurrentSpeed += 1
end

Just an example.