Variable gets set to true and false back and forth

local function onPreSimulation(deltaTimeSim: number, instance: Instance, team: string)
	local partBoundsInBox = Workspace:GetPartBoundsInBox(instance.CFrame, instance.Size)
	
	if not table.find(partBoundsInBox, hitbox) then
		if isTouching then
			if localPlayer:GetAttribute("TouchMode") == "Shoot" then
				localPlayer:SetAttribute("TouchMode", "Pass")
			end
			
			isTouching = false
			
			print("Set false")
		end
	end

	for key, part in partBoundsInBox do
		if part ~= hitbox then
			continue
		end

		if localPlayer.Team == team then
			if localPlayer:GetAttribute("TouchMode") == "Pass" then
				localPlayer:SetAttribute("TouchMode", "Shoot")
			end
			
			isTouching = true
			print("Set true")
		end
	end
end

I have this script, and it basically just keeps bugging out whenever im inside the instance area and the isTouching gets set to true and false back and forth

Im trying to detect whenever the player’s hitbox is NOT touching the instance

Player.Team isn’t a string its actually a reference to a Team object

Not sure if that will fix anything, but might be something

1 Like

Well, if so, why is isTouching being set to true? sorry, good find tho

1 Like

Not sure, more info would be helpful regarding what hitbox and isTouching are, as well as the output of the print statements