My While True Do function doesnt change values when player changes walkspeed

In this script I am trying to print the walkspeed of a player when they step on a part. The issue is, when I do my While True Do loop, the value printed doesnt change, just stays at 16 even though im still moving/slowing donw, and I dont know why. I’ve changed my script a few times, incliding making a variable for the walkspeed “Variablespeed”. Thank you in advance if you know the issue.

local Parent = script.Parent
local debounce = false

Parent.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") then
		
		if debounce == false then
			
			debounce = true
			local player = hit.Parent
			local variablespeed = player.Humanoid.WalkSpeed
			
			while true do
				wait(0.1)
				print(variablespeed)
			end
			
			
			wait(60)
			debounce = false
			
		end
	end
end)




1 Like

That’s because variablespeed is just a number and not a reference to the object.
if you do print(player.Humanoid.WalkSpeed) that should work.

1 Like

this didnt work but I think I found the problem, the WalkSpeed value is for the current set speed for the humanoid. But is there anyway to detect how fast they are going currently instead of their max possible speed?

1 Like

player.HumanoidRootPart.AssemblyLinearVelocity

If you’re wanting to get the speed in studs.

1 Like

WalkSpeed is a static value. Unless it is changed by a script, it will stay the same throughout the game. WalkSpeed represents their maximum speed. As @GetGlobals stated, you could try getting the velocity of their HumanoidRootPart instead of this approach.

1 Like