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

How can I fix this script about PlayerPoints?

Asked by
67high 10
10 years ago

So I have a game where a person gets 2 player points every 5 seconds. It was working at first, and then all of a sudden during the game it will randomly stop working. I notice it stops working most often when multiple people join the game. Its a simple script and I'm not sure why it breaks so easily. I was thinking to fix it maybe there were some lines I could add to make it reset or start over every minute in case it stops working.

PointsService = game:GetService("PointsService")
game.Players.PlayerAdded:connect(function(p)
while true do
wait(5)
game:GetService("PointsService"):AwardPoints(p.userId,2)
print("Point awarded!")
end
end)


2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Well, that loop is a bit inefficient. Try mine. The PlayerAdded Event fires when a player joins. If 2 join at one time, in your case, it'd get a bit mixed up.

PointsService = game:GetService("PointsService")

while true do
    if not (PointsService:GetAwardablePoints() <= 2) then
    for i,plr in pairs(game.Players:GetChildren()) do
        PointsService:AwardPoints(plr.userId, 2)
        wait(5)
        end
    end
end
0
I like your answer that's what I'm looking for except I just tried that script and it wasn't awarding any points. 67high 10 — 10y
0
Could you give me the error? In-game, press F9, go to server console, and tell me what's wrong. Shawnyg 4330 — 10y
0
His loop is in no way "inefficient" (other than maybe substituting the `true` with `wait(5)`). His would work just as fine as yours would, and would work accordingly; every 5 seconds after a player joins they receive 2 points. User#2 0 — 10y
0
@18, Sorry. Bit wrong choice of words. Shawnyg 4330 — 10y
View all comments (6 more)
0
Ok so Im not sure which one is the error but Ill tell you most of what it says : 67high 10 — 10y
0
Well Im guessing the error is the two red lines. The first says "-- Workspace. PointScript:3: attempt to compare boolean with number." Also a few lines later it says something about Line 3 so Im guessing that it where the error is in the script? The second place where it has a red line is right after I was added it says "WaitforChild called on an Instance that is not in a DataModel." 67high 10 — 10y
0
Oh, fail. I realized why. Try now Shawnyg 4330 — 10y
0
Try what? 67high 10 — 10y
0
My script. I edited it. Shawnyg 4330 — 10y
0
Oh oh thanks I'm still new to this site. 67high 10 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

The PlayerAdded event does a function one time only when the player joins a server, you will need to use another event.

This will help: http://wiki.roblox.com/index.php?title=Player_Points

I can't help you much more because I am new to scripting.

0
Minding how the note puts it, the point I was trying to provide was you should not just link a wiki article. Give an example, provide code, explain what's happening. Wiki-like-answers are not very helpful all the time. User#2 0 — 10y

Answer this question