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

[Not answered yet]Script only works for server, not single player?

Code:

PointsService = game:GetService("PointsService")
Stat = "KOs" 
Needed = 5 
game.Players.PlayerAdded:connect(function(p)
        repeat wait() until p:FindFirstChild("leaderstats") ~= nil
        repeat wait() until p.leaderstats:FindFirstChild(Stat) ~= nil
        p.leaderstats[Stat].Changed:connect(function(prop)
                if prop >= Needed then
	print("Has enough KO's")
                        game:GetService("PointsService"):AwardPoints(p.userId,1)
print("Has Been Rewarded")
Needed = Needed+5
print("Total Has gone up")
                end
        end)
end)

Here is the problem with the script.. It will award the player points, 'Needed' Will go up. BUT.. It acts like everyone in the server is the same person, so if anyone reaches the needed it makes it increases it for everyone else. Is there any way to fix this easily?

2 answers

You have to assign it to a local player using local so:

local Needed = 5

then make the increase local so:

local Needed = Needed +5


Here's what it should be

PointsService = game:GetService("PointsService")
Stat = "KOs" 
local Needed = 5 
game.Players.PlayerAdded:connect(function(p)
        repeat wait() until p:FindFirstChild("leaderstats") 
        repeat wait() until p.leaderstats:FindFirstChild(Stat)
        p.leaderstats[Stat].Changed:connect(function(prop)
                if prop >= Needed then
    print("Has enough KO's")
                        game:GetService("PointsService"):AwardPoints(p.userId,1)
print("Has Been Rewarded")
local Needed =  Needed+5
print("Total Has gone up")
                end
        end)
end)

1 comment

0

Nope, still doesn't work correctly.

You have to do it in a Local Script and have it do

game.Players.LocalPlayer.Leaderstats.Whatever.Value

there.

2 comments

0

I don't believe that player points can be in a local script.

0

leaderstats*

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