In my game, there is an area called a campsite. Players, assuming the campsite is their property, can enter this area and receive a gun. This gun is removed from their inventory upon exiting the area. I made this using Region3, and it has always worked, until recently. Without ever changing anything, I tested the campsite and the player still receives the gun, but it is constantly being removed from the player’s inventory and readded, despite the player not leaving the area. There are no errors in output. I have tried a lot of things that have all been unsuccessful, including changing the character part that is detected by the area from HumanoidRootPart to Torso and Head and disabling other scripts that could have caused the issue. I have a pretty vast knowledge of scripting, but I have never encountered anything like this. If anyone could help me, I would greatly appreciate it.
local Campsite = script.Parent
local Pos1 = Campsite.Position - (Campsite.Size / 2)
local Pos2 = Campsite.Position + (Campsite.Size / 2)
local Region = Region3.new(Pos1, Pos2)
game.Teams.Campers.PlayerAdded:Connect(function(player)
if player.Character:WaitForChild("Property").Value == "Campsite1" then
local Character = player.Character:WaitForChild("HumanoidRootPart")
local Backpack = player.Backpack
while wait() do
local partsInRegion = workspace:FindPartsInRegion3(Region)
if table.find(partsInRegion, Character) and #Backpack:GetChildren() == 0 and not Character.Parent:FindFirstChild("Gun") then
game.ServerStorage.Gun:Clone().Parent = Backpack
elseif not table.find(partsInRegion, Character) then
Backpack:ClearAllChildren()
for _, object in pairs(Character.Parent:GetChildren()) do if object:IsA("Tool") then object:Destroy() end end
end
end
end
end)