Hi, I'm working on a game that involves players that touch an object to earn money, and then that object reappears 5 seconds later so that they can touch it and earn money again. The issue is that once a player touches it (I'll use Player1 in this example), it works fine and Player1 gets his money increased. However if Player2 touches the block, then Player1 still gets the money. Here's the script:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
money = Instance.new("IntValue")
money.Name = "Money"
money.Value = 0
money.Parent = leaderstats
end)
local playerService = game:GetService("Players")
local serverStorage = game:GetService("ServerStorage")
-- Treasure Chest 50 spawn and destroy
local trez50 = serverStorage.TreasureChest50
local function spawnTreasure50()
local clone = trez50:Clone()
clone.Parent = workspace
clone.Touched:Connect(function(hit)
local parent = hit.Parent
if (not parent:IsA("Model")) then return end --we don't want to check if the touched Part's parent is a Player, if the parent isn't a Model, since all Players' Characters are Models.
local player = playerService:GetPlayerFromCharacter(parent) --check if the Model is a Character of a Player.
if (player) then
clone:Destroy()
money.Value = money.Value + 50
delay(5, function() spawnTreasure50() end) --comment this out, if you don't want the coin to spawn after it's destroyed, and want to call it yourself sometime later.
end
end)
end
spawnTreasure50()
(Thank you to the guy from this site that helped me write the second portion there that respawns the chest) I believe that the issue probably has something to do with the first function being specific to a player, but I'm not sure how else to get everyone on the board with variable amounts of money. Any help would be appreciated! Thank you! Let me know if I need to provide any more info.

2 comments
likewise.
Haha wow thanks so much man I appreciate the help. I'm surprised I didn't catch that easy fix :)