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)
The problem is that touching something most often touches it dozens of times at once, since your character is moving while touching it. I think a better way to handle this is by having it give you the amount when you Click on it rather than touch it.