When a certain player joins (i.e. Me) they get all player points in the games budget. How would I do that?
How do I make a player joined player point giver?
1 answer
This code is taken directly from Player Points
This sample will give a point to a player when he or she joins the game. The point will only be awarded if the game has points to give and if the player has not gotten any points in the game yet.
-- 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
PointsService:AwardPoints(player.userId, 1)
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)
This line:
PointsService:AwardPoints(player.userId, 1)
Gives you 1 point.
I think you should be able to change the number "1" with pointsToAward
PointsService:AwardPoints(player.userId, pointsToAward)
We can do this because we define pointsToAward with this line:
local pointsToAward = PointsService:GetAwardablePoints()
That line returns a int-value that tells us how many points we can award to players.
Only problem we get now is, that you only get points the first time you join, so we need to remove universeBalance
So the line would look like this:
-- 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()
if ( pointsToAward > 0 ) then
PointsService:AwardPoints(player.userId, 1)
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)
And at last you need to check if it's you that has joined before you give the points. It only takes a little editing so the line ends up looking like this:
-- 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()
if ( pointsToAward > 0 ) and player.Name == "INSERT PLAYER NAME HERE" then
PointsService:AwardPoints(player.userId, 1)
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)
Hope that works, but I can't, however, guarantee that it works.
This discussion is preserved as it was. New answers, comments, and votes are closed.
