I have this script that uses ZonePlus which creates a zone that gives player’s a sword when stepped in, and removes the tool from their hand when stepped out of. However, if the player unequips the tool, it stays in their backpack. How would I go about checking if the sword is in the player’s backpack and removing it so.
-- Get ZoneService
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local ZonePlus = require(4664437268)
local ZoneService = require(ZonePlus.ZoneService)
local starterGui = game:GetService("StarterGui")
-- Setup zone
local group = workspace.SwordArea
local zone = ZoneService:createZone("SwordArea", group, 0)
-- Create a safe zone by listening for players entering and leaving the zone
local safeZoneCheckInterval = 0
local swordAreaName = "SFSword"
local sword = game.ServerStorage.ClassicSword
sword.Name = swordAreaName
local connectionAdded = zone.playerAdded:Connect(function(player)
local char = player.Character
local swordarea = char and char:FindFirstChild(swordAreaName)
if not swordarea then
swordarea = sword:Clone()
swordarea.Parent = char
--//Unequips tools
print(player.Name.." is in safe zone")
end
end)
local connectionRemoving = zone.playerRemoving:Connect(function(player)
local char = player.Character
local swordarea = char and char:FindFirstChild(swordAreaName)
if swordarea then
swordarea:Destroy()
print(player.Name.." is not in safe zone")
end
end)
zone:initLoop(safeZoneCheckInterval)