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