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

Give Player That Touched Part Coins System?

Hi! I'm trying to make a system where a player touches a part that gives them coins, then they cant get any more coins from that specific part. I already have the leaderstats and datastore for the coins.

1 comment

0

fire a touched event that gives the player the coins and use an if statement to check if the player has reached the amount of coins that the part can give

1 answer

✓ Accepted answer

I suggest figuring out Datastore2 or Nexus Datastore because they are more customizable and have built in functions that make it easier to code leaderstats, if you understand it of course. But if you would rather not, use and edit this at will.

local coinGiven = false
local part = script.Parent

part.Touched:Connect(function(hit)
	if hit.Parent.Humanoid then -- checks if it is a player or npc or not from if it has a humanoid or not	
	local char = hit.Parent
	local player = game.Players:GetPlayerFromCharacter(char)
	local leaderstats -- get the leaderstats here from player.
	if not coinGiven then -- if they havent gotten a coin then run this
		coinGiven = true -- stops it from running again
		-- Increment coins here
	end
end)

4 comments

0

an npc can have a humanoid

0

Thanks! I will definatly try this.

0

Yes, I know. I wrote check if it is a player or an npc. I wasn't excluding this. Btw coolrocitizen, if you are satisified with the result of my answer, please accept my answer. It helps me out a lot, thanks!

0

I need it so that other players can also get the coins, not just the first player that gets it

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