How to limit the players speed without using walkspeed?

When a player enters a zone like a part zone or something I want their speed to be limited to like about half but I don’t know how to do this because I have tried using velocity and math.clamp but it did not work and I floated in the air.

Is this possible to do without using WalkSpeed?

Re-clarification:

I want to be able to control the speed that the player moves without using walkspeed, I want to be able to set the max speed I want (studs per second) and I want it to be somewhat exact. its like walkspeed but only not walkspeed, using some other thing like a bodymover or velocity. I do not know how to do this help is and will be appreciated!

1 Like

You can set their WalkSpeed, which is a property of Humanoid.

You can read more about it here.
Here is a code sample for now:

part.Touched:Connect(function(hit)
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    if (plr == nil) then return end

    local char = plr.Character
    if (char:FindFirstChild("Humanoid") == nil) then return end
    if (char.Humanoid.Health == 0) then return end

    char.Humanoid.WalkSpeed = 8 -- the default walkspeed is 16, so 8 is half of 16
end)

I will edit the post with a gif showing the result.


As you see, when you touch the part, it slows them down.

Here is another example that uses TouchEnded that works like a zone:

local function check(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if (plr == nil) then return end

	local char = plr.Character
	if (char:FindFirstChild("Humanoid") == nil) then return end
	if (char.Humanoid.Health == 0) then return end
	
	return char
end

local part = game.Workspace.Part

part.Touched:Connect(function(hit)
	local char = check(hit)
	if (char == nil) then return end

	char.Humanoid.WalkSpeed = 8 -- the default walkspeed is 16, so 8 is half of 16
end)

part.TouchEnded:Connect(function(hit)
	local char = check(hit)
	if (char == nil) then return end

	char.Humanoid.WalkSpeed = 16 -- return them to the default walkspeed
end)

This is the result:

2 Likes

Sorry I meant not using walkspeed
I want to use something like velocity to limit the players speed

It might be possible using bodyVelocity

1 Like

You can:

  • Use a BodyVelocity
  • Only turn on the BodyVelocity when the speed is above the BodyVelocity.Velocity
1 Like

This is the script I have got so far but it does not work am I doing something wrong?

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

local LocalPlayer = Players.LocalPlayer

wait(5)

local GetMass = function(Model)
	local Mass = 0
	for _, Value in pairs(Model:GetDescendants()) do
		if Value:IsA("BasePart") then
			Mass = Mass + Value:GetMass()
		end
	end
	return Mass * workspace.Gravity
end

local Mass = GetMass(LocalPlayer.Character)

local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(Mass, Mass, Mass)
BodyVelocity.Parent = LocalPlayer.Character.PrimaryPart

while true do
	BodyVelocity.MaxForce = Vector3.new(Mass, Mass, Mass)
	BodyVelocity.Velocity = -LocalPlayer.Character.PrimaryPart.Velocity
	RunService.RenderStepped:Wait()
end

I have tried using body velocity but it does not seem to be working

I’m wrong, sorry about that! I had forgotten how BodyVelocities work. Here is some code:

local MAX_SPEED = 20

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

local LocalPlayer = Players.LocalPlayer

wait(5)

local humanoidRootPart = LocalPlayer.Character.PrimaryPart
while true do
	local velocity = humanoidRootPart.AssemblyLinearVelocity
	if velocity.Magnitude > MAX_SPEED then
		local mass = humanoidRootPart.AssemblyMass
		local impulse = (velocity.Unit*MAX_SPEED - velocity)*Vector3.new(mass, mass, mass)
		humanoidRootPart:ApplyImpulse(impulse)
	end
	RunService.Stepped:Wait()
end

It might not work well with characters though, the character controller tends to override physics changes.

This script works but if I set max speed to zero then it still will stop the player completely how can I fix this.

Do you know any other ways of doing this because it is really important that I find alternative that I can control like WalkSpeed.

To my understanding there is no other way to slow down the player without changing their walkspeed.

This is interesting and may be useful…

I am not looking to overhaul the whole movement system I am just looking to limit the players speed like changing walkspeed from 16 to 8 just using something else other than WalkSpeed for example Velocity but that seems to be a dead end so far

What’s the point not to use walkspeed? It just seems like a route to a long time of code; is there a reason for this? Because if you want to slow down the player, I would use @RecanValor’s method. Can you enlighten me on why you don’t want to use walkspeed @xDeltaXen?

1 Like

WalkSpeed is not an instant change in walkspeed I ned it to go from like Velocity.Magnitude = 16 to Velocity.Magnitude = 8 instantly but if I change walkspeed then It will not be an instant change it will be a quick change but it wont instantly go from a Magnitude of 16 to a magnitude of 8.

then just set the velocity.magnitude of the character to 0 and set the walkspeed to 0 and then after you do that instantly set the walkspeed to the desired speed

Doing Velocity = Vector3.new(0, 0, 0) will stop the player completely

right so you do it and follow it up with the speed you want on the next line

I want it to slow down the player not stop and start them every time

what?? its sounds like you want it to instantly go from a set speed to a lower one instantly, but the problen is that changing walkspeed isnt instant.

what i was saying is that you just set velocity to 0 and then instantly set it to the speed you want after that.

if that still doesnt work or if i dont understand you maybe you use a number tween or something

1 Like