Still have questions? Join our Discord server and get real time help.
0

Chest Script Gives Infinite Money Instead of Set Amount?

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
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)


3
Use a debounce. Rheines 582 — 2mo
0
You should use GetPlayerFromCharacter not findFirstChild from players. It is very simple: local thisplr = game.Players:GetPlayerFromCharacter(h.Parent) suspectshot108 217 — 2mo

0

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.

0
True, however after those dozen touches the chest still disappears. For me this is not the case, The players can stand on the chest and infinitely collect from it without it ever dissappearing GlobeHousee 48 — 2mo
0
If the server lags you can still click it more than once until the chest disappears. Rheines 582 — 2mo