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

How can I fix this script about PlayerPoints?

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

✓ Accepted answer

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

10 comments

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.

0

Could you give me the error? In-game, press F9, go to server console, and tell me what's wrong.

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.

0

@18, Sorry. Bit wrong choice of words.

0

Ok so Im not sure which one is the error but Ill tell you most of what it says :

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

0

Oh, fail. I realized why. Try now

0

Try what?

0

My script. I edited it.

0

Oh oh thanks I'm still new to this site.

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.

1 comment

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.

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