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

Get points for completing an obby?

My friend and I are currently working on a game where you complete obbies in order to level up. However we're not sure on how to work the script. We've both had a look at sdfgw's tutorials and we wanted to challenge ourselves so we knew if we understood it enough.

However, after hours of trying, we've still not got it. Could someone help us? We'd be VERY grateful.

3 answers

You need to learn about points. Try the Points tutorial.

OR

Take this script

-- declare service
local PointsService = Game:GetService("PointsService")
 
-- Bind function to player added event
game.Players.PlayerAdded:connect(function(player)
	-- Get total number of points the game has available
	local pointsToAward = PointsService:GetAwardablePoints()
	-- Get total number of points this game has already awarded to the player
	local universeBalance = PointsService:GetGamePointBalance(player.userId)
	-- Check if the game has points to award and if the player hasn't gotten any points yet. 
	-- If both are true, then give the player a point.
	if ( pointsToAward > 0 and universeBalance == 0) then
		-- pcall here, as AwardPoints *will throw an error* if another server has awarded the
		-- points that were available between us checking how many were available and
		-- us actually awarding the points. There is currently no way to avoid this pcall,
		-- whenever you AwardPoints you should always wrap it in a pcall.
		pcall(function()
			PointsService:AwardPoints(player.userId, 1)
		end)
	end
end)
 
-- Bind function to when points are successfully awarded
PointsService.PointsAwarded:connect(function(userId, userBalanceinUni, userBalance)
	-- Show message indicating that a player has gotten points
	local message = Instance.new('Message', game.Workspace)
	message.Text = "Point awarded to " .. userId .. ". This player now has " .. userBalance .. " points total!"
	wait(5)
	message:Destroy()
end)

Then watch the whole tutorial.

You can't magically make it pop out from thin air if you don't know how to do it.

Best regards, Nathan.

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