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

How can I make this script update without a while true loop?

Asked by 5 years ago
game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new('Model')
    leaderstats.Name = 'leaderstats'
    leaderstats.Parent = player
    local JumpPower = Instance.new('IntValue')
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char.Humanoid
    JumpPower.Value= 0 + hum.JumpPower
    JumpPower.Parent=leaderstats
    JumpPower.Name='Score'


    end)

How can I make this script update JumpPower.Value without a while true loop?

0
You could use an event? User#25115 0 — 5y

1 answer

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

Use humanoid.Changed:Connect(function() ... end) you can see more here: Roblox Wiki - Changed

Here is a example:

workspace.Baseplate.Changed:Connect(function()
    print("Baseplate changed!")
end)

Here is your fixed script:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new('Model')
    leaderstats.Name = 'leaderstats'
    leaderstats.Parent = player
    local JumpPower = Instance.new('IntValue')
    local char = player.Character or player.CharacterAdded:Wait()
    local hum = char.Humanoid
    JumpPower.Value= hum.JumpPower
    JumpPower.Parent=leaderstats
    JumpPower.Name='Score'
    hum.Changed:Connect(function()
    JumpPower.Value = hum.JumpPower
    end)
end)

Hope it helped :D

Errors? tell-me on comments.

0
The leaderboard still doesn't update. jalbraek 29 — 5y
0
You changed the humanoid jump with server? yHasteeD 1819 — 5y
0
why use 0 + hum.JumpPower instead of just hum.JumPower? 0 + x = x theking48989987 2147 — 5y
0
I used a local script. I wanted to increase jump power when the player pressed space. jalbraek 29 — 5y
0
Use ServerScript for change the value, or use RemoteEvents. yHasteeD 1819 — 5y
Ad

Answer this question