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

how to fix a highscore counter with a replicated storage value?

Asked by
hokyboy 270 Moderation Voter
4 years ago
while true do
    wait(5)
if game.ReplicatedStorage.Score.Score.Value > game.Players.LocalPlayer.leaderstats.fightscore then do
game.ReplicatedStorage.Score.Score.Value = game.ReplicatedStorage.Score.Score.Value
end
end
end

so this script is in my serverscript service i want it to only work when the status of the highscore is changed also the script wont work!

1 answer

Log in to vote
1
Answered by 4 years ago

Main problem: Script not working

Your script doesn't work because you set the value of the score to itself

game.ReplicatedStorage.Score.Score.Value = game.ReplicatedStorage.Score.Score.Value

I guess what you're trying to do is to set the value in the leaderstats to what is in ReplicatedStorage, so:

game.Players.LocalPlayer.leaderstats.fightscore.Value = game.ReplicatedStorage.Score.Score.Value

Secondary problem:

Inserting a 5-second wait() is really inefficient. Instead, you could use :GetPropertyChangedSignal(string property), so:

game.ReplicatedStorage.Score.Score:GetPropertyChangedSignal("Value"):Connect(function()

Your fixed script would be:

game.ReplicatedStorage.Score.Score:GetPropertyChangedSignal("Value"):Connect(function()
    game.Players.LocalPlayer.leaderstats.fightscore.Value = game.ReplicatedStorage.Score.Score.Value
end)
Ad

Answer this question