How would I fix this Region3 script so when the player steps out, the sword gets deleted?

Hi DevForum! The title is self explanatory, I just want to know how I would fix this script so when the player steps off the platform, the sword gets removed from their character/backpack.

Script:

local Found = false

while wait() do
	Found = false
	local region = Region3.new(workspace.SwordFightZone.Main.Position - (workspace.SwordFightZone.Main.Size/2), workspace.SwordFightZone.Main.Position + (workspace.SwordFightZone.Main.Size/2))

	local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


	for _, part in pairs(parts) do
		if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
			print("Player was found")
			Found = true
			break
		else
			Found = false
			print("Player was not found in region")
		end
	end

	if Found == true then
		if not game.Players.LocalPlayer.Backpack:FindFirstChild("Sword") or not game.Players.LocalPlayer.Character:FindFirstChild("Sword") then
			local sword = game.ReplicatedStorage.Sword:Clone()

			sword.Parent = game.Players.LocalPlayer.Backpack

			break	
		end
	else
		if game.Players.LocalPlayer.Backpack:FindFirstChild("Sword") then
			game.Players.LocalPlayer.Backpack.Sword:Destroy()
		elseif game.Players.LocalPlayer.Character:FindFirstChild("Sword") then
			game.Players.LocalPlayer.Character.Sword:Destroy()
		end
	end
end
2 Likes

You should look into using the Zone+ module. It’s very simple and easy to use.