How to save the original walk speed and get it back

Hey so I need to save the original walk speed and get it back so if the player has 2 times speed it will go back to their speed instead of for example a set 16 walk speed. This is the script I have, how do I change it to implement this? Thanks!





script.Parent.HitPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Name ~= "Customer" then
			if hit.Parent.Name ~= "VIP" then

				hit.Parent.Humanoid.WalkSpeed = 2
				repeat wait() until game.Players:GetPlayerFromCharacter(hit.Parent):DistanceFromCharacter(script.Parent.HitPart.Position) > 6.17
				hit.Parent.Humanoid.WalkSpeed = -- I WANT THE ORIGINAL SPEED





			end

		end

	end
end)


Store their speed in something outside of the function, then change their speed. Whenever you need to revert their speed back to their original speed, reference the place you stored it in (e.g. a variable).

1 Like
script.Parent.HitPart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if hit.Parent.Name ~= "Customer" then
			if hit.Parent.Name ~= "VIP" then

				local original_Speed = hit.Parent.Humanoid.WalkSpeed

				hit.Parent.Humanoid.WalkSpeed = 2
				repeat wait() until game.Players:GetPlayerFromCharacter(hit.Parent):DistanceFromCharacter(script.Parent.HitPart.Position) > 6.17
		
				hit.Parent.Humanoid.WalkSpeed = original_Speed

			end
		end
	end
end)
1 Like

Would recommend throwing a debounce in there

1 Like

just needed to add a debounce and it worked perfectly!