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

How to make a part in workspace award points under the player when touched?

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)

3 comments

0

Where is 'awardpoints' function? .-.

0

The function is at the top of the script and works fine. My main question is how can i make the coin count towards the points when touched in game if the points are under player.

0

Why are you using in pairs if you want it to award just the player who touches it?

1 answer

✓ Accepted answer

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!

5 comments

0

Please ignore the in pairs my bad I was tired at the time of writing this. Thank you for your response. My main issue is I have the points stored under the player it is private and not part of the leaderstat. I have a GUI the reflect the points value for each player instead. The coin is sitting in workspace and i have a main script for the game under ServerScriptService. I have a defined functi

0

just change the variable points to where the stat is located thats all you need to do

0

Alrighty, and put this script under the coin itself or within the main game script?

0

Under the coin itself.

0

It worked! Thank you for the help.

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