Help send 1 remote event instead of while wait do

hello, i have a while true do script that sends a remote event to do something, but since its always checking its also always sending a remote event which makes it very laggy, how do i make it always check like how its doing, but only send a remote event when it changes?

local Tool = script.Parent
local Event = game.ReplicatedStorage.HIDINGSPOT

local IsEquipped = false

Tool.Equipped:Connect(function()
	IsEquipped = true
	
end)	

Tool.Unequipped:Connect(function()
	IsEquipped = false
end)

local Dark1 = game.Workspace.DetectableSafeRooms.SafeRoom1
	local players = game:GetService("Players")

	while wait() do
		local touching = game.Workspace:GetPartsInPart(Dark1)
		for i, v in pairs(touching) do
			if v.Parent:FindFirstChild("Humanoid") ~= nil then
				local player = players:GetPlayerFromCharacter(v.Parent)
			if IsEquipped then
				Event:FireServer("Dark1")
				end
			end
		end
	end

just change it when its equipped/unequipped, not while wait

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.