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

I don't know how to make a players speed equal to a leaderstat?

Hi there, I'm having a problem making a players speed equal to a speed leaderstat.

So here i have made a leaderstat for the players speed.

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	
	local SpeedValue = Instance.new("IntValue")
	SpeedValue.Name = "Speed"
	SpeedValue.Value = 2
	SpeedValue.Parent = stats
end)

Here i have made it so when a player activates a tool, a remote event is fired (It also has a cooldown script)



local cooldown = false


script.Parent.Activated:Connect(function()
	if cooldown == false then
		cooldown = true
	game.Workspace.MainEvent.AddSpeed:FireServer()
	script.Parent.Enabled = false
	wait(1.2)
	script.Parent.Enabled = true
	cooldown = false
	end
end)

And here i have made a script inside of the Workspace(with the remote event inside of it named "AddSpeed").

script.AddSpeed.OnServerEvent:Connect(function(player)
	player.leaderstats.SpeedValue.Value = player.leaderstats.SpeedValue.Value + 1
end)

This code does work as i can see the speed going up when I activate the tool. The issue i am now having is linking up the speed leaderstat with the players humanoid speed value. I was just wondering if somebody could give me a brief example on how i could do this?

1 comment

0

You could put in the playeradded function a loop that constantly checks for the value of the Speed. And in the same loop make say something like player.Character.Humanoid.WalkSpeed = player.Character.Humanoid.WalkSpeed +SpeedValue.Value

1 answer

✓ Accepted answer

Try this:

player.Humanoid.Walkspeed = player.Humanoid.Walkspeed + player.leaderstats.SpeedValue.Value

What it does is set the player's Walkspeed as their current walkspeed plus how many speedvalue they have. I'm sure you can put it in your script in a way.

1 comment

0

Thanks it worked!

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