Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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?

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 DarkDanny04 407 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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.

0
Thanks it worked! charman444 -1 — 4y
Ad

Answer this question