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

Give player points from a part?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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.

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. Grenaderade 525 — 9y
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. Thewsomeguy 448 — 9y
0
Grenade, you can only award points from roblox game servers Thewsomeguy 448 — 9y
0
Yeah, that's why I said it worked. Because it was at the end of the script. Grenaderade 525 — 9y
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. Grenaderade 525 — 9y
Ad
Log in to vote
0
Answered by 4 years ago

You need to publish the game. It worked for me.

Answer this question