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 6 years ago
01game.Players.PlayerAdded:Connect(function(player)
02 
03    local leaderstats = Instance.new('Model')
04    leaderstats.Name = 'leaderstats'
05    leaderstats.Parent = player
06    local JumpPower = Instance.new('IntValue')
07    local char = player.Character or player.CharacterAdded:Wait()
08    local hum = char.Humanoid
09    JumpPower.Value= 0 + hum.JumpPower
10    JumpPower.Parent=leaderstats
11    JumpPower.Name='Score'
12 
13 
14    end)

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

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

1 answer

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

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

Here is a example:

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

Here is your fixed script:

01game.Players.PlayerAdded:Connect(function(player)
02 
03    local leaderstats = Instance.new('Model')
04    leaderstats.Name = 'leaderstats'
05    leaderstats.Parent = player
06    local JumpPower = Instance.new('IntValue')
07    local char = player.Character or player.CharacterAdded:Wait()
08    local hum = char.Humanoid
09    JumpPower.Value= hum.JumpPower
10    JumpPower.Parent=leaderstats
11    JumpPower.Name='Score'
12    hum.Changed:Connect(function()
13    JumpPower.Value = hum.JumpPower
14    end)
15end)

Hope it helped :D

Errors? tell-me on comments.

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

Answer this question