Need Help for this pvp zone script (Fixed)

(Fixed) You can copy all codes if you want I won’t delete the post

Greetings, developers. I kindly request your assistance if you have any knowledge of scripting. The scenario is as follows: when a player enters the PvP zone, a tool that activates fighting scripts is given to them. However, when the player leaves the PvP zone, the fighting script must be deactivated and the value in the replicated storage must be set to false, if a player has equipped the tool and then leaves the PVP zone then It deletes the tool but the value stays true and the script is still working. I think to fix this I must unequip the tool first and then delete it from player’s backpack
video:Imgur: The magic of the Internet

scripts:
Item Remover script:

local Tool = game.ReplicatedStorage.Fists 
function onTouched(hit)
	game.ReplicatedStorage.Isworking.Value = false
	local human = hit.Parent:findFirstChild("Humanoid")
	if (human ~= nil) then
		local character = hit.Parent
		local player = game.Players:GetPlayerFromCharacter(character)
		local backpack = player.Backpack
		local tool = backpack:FindFirstChild(Tool.Name) or character:FindFirstChild(Tool.Name)
		if tool then
			game.ReplicatedStorage.Pvpzone.Value = false
			tool:Destroy()
		end
	end
end

script.Parent.Touched:connect(onTouched)

While loop which does not work:

while wait(0.1) do
	if game.ReplicatedStorage.Isworking.Value == true then
		script.Parent.PunchingScript.Enabled = true
	elseif game.ReplicatedStorage.Isworking.Value == false  then
		script.Parent.PunchingScript.Enabled = false
	end
end

Checker script which also does not work:

local player = game.Players.LocalPlayer
local backpack = player.Backpack

function hasTool(toolName)
	for _, item in pairs(backpack:GetChildren()) do
		if item.Name == toolName then
			return true
		end
	end
	return false
end

if hasTool("Fists") then
	-- Do nothing, the player has the tool
else
	game.ReplicatedStorage.Isworking.Value = false
end
1 Like

What do you mean by “doesn’t work”?

If your PunchingScript is not a local script, that’s why it doesn’t disable, .Enabled isn’t replicated, if you are changing it’s Enabled property from a local script, it won’t actually disable the script.

Also i don’t recommend using a Touched event for detecting when the player leaves the area, it has some downsides, for example doesn’t detect if the player is going at high speed, or if an exploiter deletes the wall, the script wont run it anymore, you should use a Region3 for the pvp area.