Need help with coin pickup system

so I am trying to create a coin system where every player can collect the same coin and the coin has its own cool down for each of them, there is a system like this out there in a game called (Eg), I know I shouldn’t be asking for this type of stuff here but I have tried 3 or 4 systems now and nothing works, all I want to know is how I could go about doing this,

thanks in advance to anyone who helps.

Use your preferred method to see if a player is touching the coin, eg. a .Touched event with a local script. Once a player touches the part, use a remote function to tell the server that the player has touched the coin. In a server script, create a table of players currently in the game(by player name or UserID). When the remote event is triggered, you can very easily add the time that the coin was touched to the table as indexed by player name or UserID, and check to see if the player should be able to collect the coin again based on the prior time the coin was touched.

There are a few other ways to do this, but this is the most simple.

how could i be able to set up the time thing you talked about? i have not scripted in quite a while as I am mainly a modeler so if you could help me out that would be great

Here is an example script. It doesn’t include anything about checking to see if the coin is touched, there are multiple methods for that ex: using a .touched event, but it does go over the timing aspect.

Players = game:GetService("Players")

local PlayerTable = {}

local CoinCooldown = 5 -- the amount of time a player has to wait to pick the coin up again in seconds

for i,player in pairs(Players:GetPlayers()) do -- to note players that exist at the moment the script is initially ran
	onPlayerAdded(player)
end

Players.PlayerAdded:Connect(onPlayerAdded) -- to note players that joined after this script was initially ran

function onPlayerAdded(player) -- adds players to the table, sets the time they initially collected the coin at 0
	PlayerTable[player].CoinTime = 0
end

function onCoinTouch(Player, TouchTime) -- TouchTime is the time the player touched the coin by using os.time or tick()). Just pass this information when you call this function using your preferred method to see when the coin is touched
	if (TouchTime - PlayerTable[Player].CoinTime) >= CoinCooldown then -- checking to see if enough time has passed to collect the coin
		coinFunction()
		PlayerTable[Player].CoinTime = TouchTime --setting the new time at which the player last collected the coin
	end
end

function coinFunction() --whatever happens when the player collects the coin
	
end

edit: I didn’t test this script but it is a good outline of the general idea.

1 Like

thank you for your help, i have been trying for 2 days now, thank you again and have a great day/night.