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

Give player points from a part?

I was having some fun making a quick game, when I came across a problem, I can't award player points to players when they touch a part. It is supposed to award them 1 Player Point. Everything else works except the Player Point part. (I tested the script without the player point part, it worked fine)

User = game.Players:GetPlayers()
bux2 = game.Lighting.BUX:Clone()
script.Parent.Touched:connect(function()
	local PointsService = game:GetService("PointsService")
	PointsService:AwardPoints(User.userId, 1)
	game.Workspace.ROBUX.Value = game.Workspace.ROBUX.Value + 1
	bux2.Parent = workspace
	script.Parent:Destroy()
end)

This is a one player game so the variable won't give it to thousands of people

2 answers

✓ Accepted answer

The issue is that you are trying to assign player points to an array of players.

Using :GetPlayers() only gets a list of the players, but not a specific player.

Rather, you can attempt to get the player via the brick that is touched by using the GetPlayerFromCharacter method.

local User = nil;
local bux2 = game.Lighting["BUX"]:Clone()
local PointsService = game:GetService("PointsService")
script.Parent.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
workspace["ROBUX"]Value = workspace["ROBUX"].Value + 1
PointsService:AwardPoints(plr.userId,1)
bux2.Parent = workspace
script.Parent:Destroy()
end
end)

Explanation

When something fires the 'Touched' event, you can bind a variable that is basically the object that 'Touched' the referenced part.

In this case, we called it 'hit'

Roblox has a built-in method called GetPlayerFromCharacter which allows you to reference the Player if you can find the Character of it in Workspace.

Once we referenced the player properly, we awarded him/her.

5 comments

0

Got this from this output: "Processing PointsService:AwardPoints error: HTTP 403 (HTTP/1.1 403 Forbidden). userId = 37515669" It's in test mode so, it should be working.

0

You answered it better than I did (mine was short because apparently this site hates mobile devices). But you removed line 6 of his code.

0

Grenade, you can only award points from roblox game servers

0

Yeah, that's why I said it worked. Because it was at the end of the script.

0

And it since it is at the end of the script, that means nothing above was wrong, because it was the only thing in the output.

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