Hi, this chest script works by being touched, giving the player their gold and sending the chest to Lighting as a way to make it despawn for 45 seconds. The thing is, this script works when picking one up one at a time or small amounts of chests are being used in the map. However, when there are lots of players are on and there are lots of chests, the chests will break and be able to be touched and give money without despawning into Lighting, giving players infinite money basically. When I tried to assign the chests random numbers in their name so the script knows which specific chest to put back into position, this solution did not end up working.
What could be the problem here?
amnt = math.random(50,100)
chest = script.Parent
chest.Name = ("Chest" .. math.random(0,500))
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Gold")
if (score~=nil) then
score.Value = score.Value + amnt
print("Touch")
chest.Parent = game.Lighting
wait(45)
game.Lighting:FindFirstChild(chest.Name).Parent = game.Workspace
end
end
end
end
end
script.Parent.Special.Touched:connect(onTouched)

2 comments
Use a debounce.
You should use GetPlayerFromCharacter not findFirstChild from players. It is very simple: local thisplr = game.Players:GetPlayerFromCharacter(h.Parent)