Giving a player their own entity of an item

Hi, this may seem trivial to some of you guys but after listening to some feedback on my obby, it’s become apparent I need to change a few things.

I have on my obby checkpoint sounds and coin givers. But people have reported that 1, they can hear the checkpoint sound when someone else touches a checkpoint, and 2, my coin givers are set to wait function of several minutes to prevent coins mining, but of course other players then can’t grab the coins.

My question is, how would I make it so each player has their own entity of an item that doesn’t affect other players.

1 Like

Use a dictionary to store stuff like this.
Sort of a debounces dictionary.
Example:

local players_db = {
["Player1"] = true,
["Player2"] = true
}

For the sounds issue, there are 2 properties about distance in the Sound. You should play with it.

1 Like

I figured it out… Thanks for helping. Your example showed me what I need to look at. Seeing the {} symbols, I knew it was an array. So I got playing. :slight_smile:

local player = game:GetService("Players")
local enabled = {}

script.Parent.Touched:Connect(function(hit)
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid and not enabled[player] then
		enabled[player] = true
		
		local Coins = player.leaderstats.Coins
		Coins.Value = Coins.Value + 5
		task.wait(30)
		enabled[player] = false

	end
end)

Other things I never quite understood, now stand out more to me.

  1. I now know why the game:GetService (“Players”) has to be called in this example…

(You can’t assign values to a leaderstats without first knowing where the leaderstats are. So we call them… This then adds a reference so the script knows where to look) This example does presume a leaderstats already exists within the ServerScriptService.

  1. I learnt a little more about debouncing (Enabled) in this case.