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

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

Asked by
lomo0987 250 Moderation Voter
10 years ago

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

Log in to vote
0
Answered by 10 years ago

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)
0
Nope, still doesn't work correctly. lomo0987 250 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

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

game.Players.LocalPlayer.Leaderstats.Whatever.Value

there.

0
I don't believe that player points can be in a local script. lomo0987 250 — 10y
0
leaderstats* systematicaddict 295 — 10y

Answer this question