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

Doesn't change the value of the leaderstat?

Asked by
lomo0987 250 Moderation Voter
10 years ago
PointsService = game:GetService("PointsService")
Stat = "KOs" 
game.Players.PlayerAdded:connect(function(p)
        repeat wait() until p:FindFirstChild("leaderstats") ~= nil
        repeat wait() until p.leaderstats:FindFirstChild(Stat) ~= nil
        repeat wait() until p.leaderstats:FindFirstChild("NextPP") ~= nil
        p.leaderstats[Stat].Changed:connect(function(prop)
                print("Value changed!")
                need = p.leaderstats:FindFirstChild("NextPP").Value
                print("Found Need")
                if prop >= need then
                        game:GetService("PointsService"):AwardPoints(p.userId,1)
                        need = need + 5 -- this is where it's messing up.
                        print("Awarded points and need has went up")
                end
        end)
end)

For some reason at line 13, need doesn't go up by 5. Everything works but that. (All of the prints and awarding player points)

Did I set it up wrong?

1 answer

Log in to vote
1
Answered by
HexC3D 830 Moderation Voter
10 years ago
PointsService = game:GetService("PointsService")
Stat = "KOs" 
game.Players.PlayerAdded:connect(function(p)
        repeat wait() until p:FindFirstChild("leaderstats") ~= nil
        repeat wait() until p.leaderstats:FindFirstChild(Stat) ~= nil
        repeat wait() until p.leaderstats:FindFirstChild("NextPP") ~= nil
        p.leaderstats[Stat].Changed:connect(function(prop)
                print("Value changed!")
                need = p.leaderstats:FindFirstChild("NextPP")
                print("Found Need")
                if prop >= need then
                        game:GetService("PointsService"):AwardPoints(p.userId,1)
                      for i = 1,1 do
                        need.Value = need.Value + 5  --This should make need +5.
                            end
                        print("Awarded points and need has went up")
                end
        end)
end)

Doing so should +5 need.

0
Tried that, didn't do anything. lomo0987 250 — 10y
0
Try again updated HexC3D 830 — 10y
0
Hmm, so I can't have the Value when defining need? lomo0987 250 — 10y
0
I don't think you can a variable equal to some objects property, i'm not really sure myself. HexC3D 830 — 10y
View all comments (4 more)
0
Typo much ^ HexC3D 830 — 10y
0
Lol, btw you forgot on line 11, it needs to be 'need.Value' Considering you took it off when it was trying to define 'need'. But with that said and it was working with that.. It's just ehh... lomo0987 250 — 10y
0
Well you can just use Data Persistence instead of using so much loops, just use p:WaitForDataReady(). HexC3D 830 — 10y
0
and yeah, it's fixed now because of the ".Value". I don't really understand why it can't have it be attached to a value :/ lomo0987 250 — 10y
Ad

Answer this question