Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Doesn't change the value of the leaderstat?

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

✓ Accepted answer
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.

8 comments

0

Tried that, didn't do anything.

0

Try again updated

0

Hmm, so I can't have the Value when defining need?

0

I don't think you can a variable equal to some objects property, i'm not really sure myself.

0

Typo much ^

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...

0

Well you can just use Data Persistence instead of using so much loops, just use p:WaitForDataReady().

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 :/

This discussion is preserved as it was. New answers, comments, and votes are closed.