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

[Not answered!]Points on every 5 kills?

PointsService = game:GetService("PointsService")
Stat = "KOs" 
Needed = 5
game.Players.PlayerAdded:connect(function(p)
        repeat wait() until p:FindFirstChild("leaderstats") ~= nil
        print("Found \"leaderstats\" object!")
        repeat wait() until p.leaderstats:findFirstChild(Stat) ~= nil
        print("Found "..Stat.." object!")
        p.leaderstats[Stat].Changed:connect(function(prop)
                print("Value changed!")
                if prop >= Needed then
                        game:GetService("PointsService"):AwardPoints(p.userId,1)
needed = needed +5
                end
        end)
end)

Edit: It can't be in a local script, so i'm going to need a different way to do it, probs put a value inside a player?

What i have been trying to do is increase the 'needed' by 5, but this does it for everyone on the server. Is there any way i can make this a local script and put it inside StarterGUI? (Don't know if that will break anything)

1 comment

0

Edited my code.

2 answers

PointsService = game:GetService("PointsService")
Stat = "KOs" 
Needed = 5
game.Players.PlayerAdded:connect(function(p)
    local needed = Needed
    p:WaitForChild('leaderstats'):WaitForChild(Stat).Changed:connect(function(prop)
        print("Value changed!")
        if prop >= needed then
             game:GetService("PointsService"):AwardPoints(p.userId,1)
	     needed = needed + Needed
        end
    end)
end)

2 comments

0

we been through this before. That doesn't work.

0

Edited.

Yeah, in fact it's way easier:

PointsService = game:GetService("PointsService")
Stat = "KOs"
Needed = 5
p = game.Players.LocalPlayer
repeat wait() until p:FindFirstChild("leaderstats") ~= nil
repeat wait() until p.leaderstats:findFirstChild(Stat) ~= nil
p.leaderstats[Stat].Changed:connect(function(prop)
       print("Value changed!")
        if prop >= Needed then
                game:GetService("PointsService"):AwardPoints(p.userId,1)
		needed = needed +5
        end
end)

You know you can use the Tab key to indent things, right?

3 comments

0

That just makes the script look 'neater'. If it's a short script I don't really care about it then.

0

"Points Service requires beta access" and line 10... stack end?

0

Nvm, I just remembered it has to be in a normal script. local scripts can't access Points Service :/

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