How do I set a minimum walkspeed?

Hello! How would I set a minimum walkspeed in my game? This wouldn’t affect PC players, but it would affect Mobile and Xbox players. I’d like it to be 8. Thanks :slight_smile:

You can do this:

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		char:WaitForChild("Humanoid"):GetPropertyChangedSignal("WalkSpeed"):connect(function()
			if(char:WaitForChild("Humanoid").WalkSpeed < 8) then
				char:WaitForChild("Humanoid").WalkSpeed = 8
			end
		end)
	end)
end)

Everytime the player’s walk speed goes below 8, it returns to 8.
This is a normal script, inside the Server Script Service

2 Likes

Thanks for the help, appreciate it <3
It doesn’t appear to work with the emulator? And I will set the solution don’t worry :slight_smile:

1 Like

No problem! If it works, please accept my answer as a solution :grinning:

Wait a second, it does not work with the emulator?

Nope. Not with the iPad emulator.

I just noticed it too, I checked and for some reason, when you use another device such as mobile, the humanoid walk speed does not change, let me see if there’s anything to do about it

1 Like

I think it does give you 8 walkspeed but its just for an instant because i think the 8 walkspeed isnt looped?

1 Like

I am sorry Ethan, I couldn’t find anything related to that, that is so strange, why does it not change the humanoid’s walk speed when you walk slowly in mobile?

1 Like

No, that’s not the problem in my code, he meant that this script does not work for mobile users, but works on PC, for some reason, in mobile devices, when you move slowly, the humanoid’s walk speed stays the same.

1 Like

Ive notice that your walkspeed remains 16 even when you go slow on mobile
https://gyazo.com/d8f8e2423f25ebc471708e7d54de058d

1 Like

That’s exactly what I have said, I have noidea how to get the humanoid’s speed when you’re on a mobile device.

1 Like

I think we dont have a solution for now…

1 Like

Is there a roblox developers support? If there is, maybe he could ask them, because that is very strange that mobile movemnt is not changing the humanoid’s movement speed.

1 Like

I don’t think that there is? But surely there would be a way to set it…

There must be Ethan, but not that I know of, maybe you can look it on the web, or contact Roblox, but I don’t know how to get the player’s speed if he is on mobile

1 Like

I believe you could look into the default control scripts located under PlayerScripts, see which part of them handles custom speed on mobile devices and edit it.

2 Likes

I don’t know what to edit though, nor where to find the correct script out of the options available. Also how will I know it works for Xbox if Xbox doesn’t have an accurate emulator?

Okay after playing with this for a while, I believe I’ve figured out a solution (at least for mobile devices).

Explanations

There is a module located under PlayerScripts.ControlModule.DynamicThumbstick. Inside it, there is a function called DynamicThumbstick:DoMove(). It passes a moveVector to function Player:Move() which seems to adjust your movement speed accordingly depending on the X Y Z values of the Vector3 you pass to it (0 = no movement, 1 = full WalkSpeed).

So, let’s use WalkSpeed 16 as an example. If 100% = 16 and 0% = 0, then we can use this formula to turn a number between 0 and 1 to the respective values between 0 and 16:

local function CalculateValFromPercent(min, max, percent)
	return max*percent + (min * (1-percent))
end

print(CalculateValFromPercent(0, 16, 0.5)) --> 8

(idk if it’s the best way to do that, as I figured it out on my own a few months ago)

Now, since a Vector3 is influenced by 3 values, we will use its Magnitude property instead of checking them separately:

local speed = hum.WalkSpeed
local vectorSpeed = CalculateValFromPercent(0, speed, currentMoveVector.Magnitude)

Now all that’s left is pump it up if vectorSpeed is below 8. To do that, we can use the Unit property of a Vector3, which returns just the direction.
(In case you’re confused, multiplying the Unit by 1 would result in speed equal to WalkSpeed. Multiplying it by the Magnitude would get us back where we started.)

So, what do we multiply it by? The answer is, the percentage value of 8, between 0 and the current WalkSpeed.
I.e. if the WalkSpeed is 16, it’d be 0.5
We’ll use this function to accomplish it:

local function CalculateValFromPercent(min, max, percent)
    return max*percent + (min * (1-percent))
end

(again made by me so idk if it’s the best)

End result:

local speed = hum.WalkSpeed		
local vectorSpeed = CalculateValFromPercent(0, speed, currentMoveVector.Magnitude)
if vectorSpeed < 8 then
	currentMoveVector = currentMoveVector.Unit * CalculatePercentFromVal(0, speed, 8)
end

Doesn’t look too complicated, does it?

The whole function with the modifications
local function CalculateValFromPercent(min, max, percent)
	return max*percent + (min * (1-percent))
end

function CalculatePercentFromVal(min, max, val)
	return 1 - (max-val)/(max-min)
end

function DynamicThumbstick:DoMove(direction)
	local currentMoveVector = direction

	-- Scaled Radial Dead Zone
	local inputAxisMagnitude = currentMoveVector.magnitude
	if inputAxisMagnitude < self.radiusOfDeadZone then
		currentMoveVector = ZERO_VECTOR3
	else
		currentMoveVector = currentMoveVector.unit*(
			1 - math.max(0, (self.radiusOfMaxSpeed - currentMoveVector.magnitude)/self.radiusOfMaxSpeed)
		)
		currentMoveVector = Vector3.new(currentMoveVector.x, 0, currentMoveVector.y)
	end
	
	local char = game.Players.LocalPlayer.Character
	if char then
		local hum = char:FindFirstChild("Humanoid")
		if hum then
			local speed = hum.WalkSpeed
			
			local vectorSpeed = CalculateValFromPercent(0, speed, currentMoveVector.Magnitude)
			if vectorSpeed < 8 then
				currentMoveVector = currentMoveVector.Unit * CalculatePercentFromVal(0, speed, 8)
			end
		end
	end

	self.moveVector = currentMoveVector
end

The modules fork for download:
PlayerModule.rbxm (109.6 KB)

How to implement:

  1. Download
  2. Put under StarterPlayerScripts, like this: image
4 Likes

Thanks so much! What about thumbstick? (What I’ll be using for the game) Also now I get more about the whole thing, tysm :slight_smile: