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

How do I make a players WalkSpeed or Health's Value change according to the value of a leaderboard?

Asked by 6 years ago
Edited 6 years ago

I've been trying to make a person's WalkSpeed and Health's Value increase by the Value of the leaderboard ( leader stats ) And this is the Script that I came up with

( Script for health that i made )

local Player = game.Players.LocalPlayer
local PlayersEnergy = Player:FindFirstChild('leaderstats'):FindFirstChild('Meme Energy')

while true do
      Player.Character.Humanoid.MaxHealth = PlayersEnergy.Value
      Player.Character.Humanoid.Health = PlayersEnergy.Value
wait(0)
end)

( Script for WalkSpeed that i made )

local Player = game.Players.LocalPlayer
local PlayersPower = Player:FindFirstChild('leaderstats'):FindFirstChild('Meme Power')

while true do
    Player.Character.Humanoid.WalkSpeed = PlayersPower.Value
wait(0)
end)

1 answer

Log in to vote
0
Answered by 6 years ago

Using while true do isn't the best way to do this, now assuming this is a local script you should use Changed instead.

local Player = game.Players.LocalPlayer
local PlayersEnergy = Player:WaitForChild('leaderstats'):FindFirstChild('Meme Energy')
local char = Player.Character or Player.CharaterAdded:Wait()

PlayersEnergy.Changed:Connect(function()
    char:WaitForChild('Humanoid').MaxHealth = PlayersEnergy.Value
end)

local Player = game.Players.LocalPlayer
local PlayersPower = Player:WaitForChild('leaderstats'):FindFirstChild('Meme Power')
local char = Player.Character or Player.CharacterAdded:Wait()

PlayersPower.Changed:Connect(function()
    char:WaitForChild('Humanoid').WalkSpeed = PlayersPower.Value
end)

This should work, if it doesn't check the output and tell me the error.

Good luck on your goal!

0
@BlackOrange Where do I place the Local Script ? SkatePro888899999 5 — 6y
0
Im increasing Meme Power's Value it doesnt seem to increase, I checked the Output no Output given about it. SkatePro888899999 5 — 6y
0
My mistake, It's finally working! Thanks. SkatePro888899999 5 — 6y
0
Np BlackOrange3343 2676 — 6y
Ad

Answer this question