I have a part, I have this script inside it (normal script):
local BankArea = script.Parent
local Position1 = BankArea.Position - (BankArea.Size / 2)
local Position2 = BankArea.Position + (BankArea.Size / 2)
local Reigon = Region3.new(Position1, Position2)
local Debounce = false
while true do
wait()
local PartsInReigon = workspace:FindPartsInRegion3(Reigon, nil, 1000)
for i, v in pairs(PartsInReigon) do
if v.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(v.Parent)
if not Debounce then
Debounce = true
Player.leaderstats.Cash.Value += 1
wait(2)
Debounce = false
end
end
end
end
So while the player is inside the part, I want to give them +1 Cash.
But the problem is that once they enter the part, and then they leave it, they still get the +1 Cash. This script is supposed to only give the player cash if they are inside the part (which it does). But it also gives the player cash once they leave the part. How do I fix this?
Thanks for any help

4 comments
try printing
Reigon.PositionandReigon.Sizeusingprint(Reigon.Position, Reigon.Size). Then add a part in workspace and set the part's position toReigon.Positionand set the part's size toReigon.Size. Tell us where the part is.The part is just next to the reigon3 part. But even if I don't walk into the new created part, it still adds the cash
I think maybe there a lot of Character's parts like arm and stuff, so it would loop all the part that has Character as it parent(yeah included Humanoid inside Character too) and give the money to the Player
Use HumanoidRootPart as hitbox, the reason why is it adding is because it's in one thread, the debounce is stopping the whole while loop and since there can be like 15 parts in the region it will stop it for whole 30 seconds, try BindableEvents to spawn the function in another thread