Hello, so I have this Region3 and whenever the character enters is inside the region3 the player should get plus 1k Coins since they are in the region but if they leave the region3 that stops. the issue with my script is that even if the player is not present in the region they will still get plus 1k coins
here is the script
local part = script.Parent-- The region3
--local db = false
local region = Region3.new(part.Position - part.Size/2, part.Position + part.Size/2)-- Formula to get the measurements bottom and top of the region
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
local character = plr.Character
if not character or not character.Parent then
character = plr.CharacterAdded:wait()
end
while true do
wait(1)
local FindParts = game.Workspace:FindPartsInRegion3(region,part)-- BuiltInFunction to check if anything is inside the Region3
for i,parts in pairs(FindParts) do-- looping through all objects are present in the region3
if parts.Name == "RightLowerArm" or "Torso" or "UpperTorso" or "RightHand" or "LeftHand" or "HumanoidRootPart" or "RightLowerLeg" then
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 1000
print(parts)
local Region3UI = game.StarterGui.Region3
Region3UI.Enabled = true
else
break
end
end
end
end)