I have a part under workspace called "Coin" I want to be able to collect this coin and when collected it updates the player points that i have stored under the player as well as the gui I have showing the player those points. My main script is under ServerScriptService. My points system does work when a player joins and plays a match they get the points and the gui updates with the new point value. There is no error output. Does there need to be a script under the coin itself? This is what I have so far under my main game script:
local Coin game.workspace.Coin.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~=nil then if Coin == true then Coin = false game.workspace.Coin.Transparency = 1 local player = game.Players:GetPlayerFromCharacter(hit.Parent) for _,Player in pairs(game.Players:GetPlayers()) do if Player:FindFirstChild("Points") then awardpoints(player, 10) end end end end
end)
I don't understand why you're using in pairs
when you are just trying to award it to the player who touches it.
script.Parent.Coin.Touched:Connect(function(hit) --wherever the part is local player = game.Players:GetPlayerFromCharacter(hit.Parent) local points = player:WaitForChild("leaderstats").Points --index where the leaderstat is stored points.Value = points.Value + 10 --award 10 points to the player end)
Note: I am writing this from scratch so if it doesn't work please let me now, if it did however please accept my answer if this helped!