Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you change player walkspeed based on leaderstat?

For example if a players leaderstat equals to 10, the player will have 10 walkspeed.

2 answers

localscript

while wait(0.1) do
  game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = game.Players.LocalPlayer.leaderstats.Speed.Value
end

Use the event :GetPropertyChangedSignal() in the walkspeed leaderstat and it will fire if a certain property changes.

For example, we put "Name" between the parenthesis. If the Name of the walkspeed leaderstats changes, this will fire. For this one, we must use "Value".

Also don't forget to do the same thing to the humanoid walkspeed.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player) -- this event will fire when a player joins
	local Leaderstats = Instance.new("Folder", Player) -- creates the leaderstats inside the Player
	Leaderstats.Name = "leaderstats"
	
	local WalkSpeed = Instance.new("NumberValue", Leaderstats)
	WalkSpeed.Name = "Speed"
	
	Player.CharacterAdded:Connect(function(Character) -- this event will fire when the player's character has loaded/respawned
		local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
		WalkSpeed.Value = Humanoid.WalkSpeed
		
		WalkSpeed:GetPropertyChangedSignal("Value"):Connect(function() -- this event will fire if the Value of WalkSpeed changes
			Humanoid.WalkSpeed = WalkSpeed.Value
		end)
		
		Humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function() -- this event will fire if the speed of player changes
			WalkSpeed.Value = Humanoid.WalkSpeed
		end)
	end)
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.