So I have a coin in my game. When a player touches the coin, the player get's 1 coin added in their leader stats. But now when another player touches the same coin which another player touched before, they don't get the money and the coin is still there. It's giving money functionality is finished when 1 player touches it and get's their money. But now the others can't get it.
Can someone please help me with this so that the other players successfully get their +1 point after someone else touched that coin? I think we can do this by making the coin locally but I don't understand how.
The coin is a model.
Here is my code:
Collect Script (this is a normal script and not a local script):
local db = true script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if db == true then db = false script.Parent.Transparency = 1 local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 script.Sound:Play() wait(1) script.Parent.Transparency = 1 wait(1) script.Parent.Transparency = 0 end end end)
Now the leader board script which adds a coin's table to the leader board;
local coins = Instance.new("IntValue", leaderstats) coins.Name = "Coins" coins.Value = 0
Note that I have added the player added event in the above script but I haven't shown it since it is not neccessary.
Thanks
By the looks of it you have incorrectly setup your debounce variable.
After you set the transparency back to 0 you need to set db back to true. Else your condition for checking debounce will fail.
local db = true local Cooldown = 10 script.Parent.Touched:connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then if db == true then db = false script.Parent.Transparency = 1 local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 script.Sound:Play() script.Parent.Transparency = 1 wait(Cooldown) script.Parent.Transparency = 0 db = true end end end)
Edit: If you want to make it so there is a cooldown between getting coins you can use wait() to fix this.
I've added my modifications to the code above.