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

Leaderstat Value Won't Change?

Asked by 5 years ago

I made this script which waits 60 seconds, then increases a leaderstat value by 1. But for some reason nothing happens to the value, and I don't get any errors on it. I feel like the answer is obvious but I have no idea how to fix it. Here's the code:

wait(1.5)
function Min(NP)
    while true do
        local Stat = NP.leaderstats["Minutes Played"].Value
        wait(60)
        Stat = Stat + 1
    end
end


game.Players.ChildAdded:Connect(Min)

I've also tried making it a StarterPlayerScripts script and the same thing happens, code below.

wait(2)
while true do
    wait(6)
    script.Parent.Parent.leaderstats["Minutes Played"].Value = 
        script.Parent.Parent.leaderstats["Minutes Played"].Value +1
end
0
Local Scripts only change to Local Player... you should use a normal script Leamir 3138 — 5y

1 answer

Log in to vote
0
Answered by
Oficcer_F 207 Moderation Voter
5 years ago

Problem with the 1st script: You used a child added function and therefore it waits 60 seconds everytime a child is added to players. You need to find the value from the player in a different way, by using remote events, local script and a script.

Problem with the 2nd script: Most likely you did this in a local script, so you cannot change the value. Therefore use a remote event and a server script to change the value.

Hope this helps, if not feel free to ask questions.

0
Ah ok. I did use a normal script for the 2nd one but no remote event. Thanks. NoahsRebels 99 — 5y
Ad

Answer this question