Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] How to check if a mouse leaves a certain part?

Hi, currently I know how to detect when a part enters a certain part but I don't know how to detect when it leaves that exact part? Help is appreciated

--/ block selection
local currentblock

local table1 = {}


while wait(1) do
	local noerror,errormsg = pcall(function()
		--/ update list
		for i,v in pairs(game.Workspace.SelectTest:GetChildren()) do
			if not v:FindFirstChild("Selection") == nil then
				print("OK")
				table.insert(table1,v)
			end
		end
		
		local mouseraycast = mouse.Target
		
		if mouseraycast then
			if mouseraycast.Parent.Parent == game.Workspace.SelectTest then
				currentblock = mouseraycast
				
				--/ clone our glow to the block
				local glow = replicatedstorage.MechanicEffects.SelectEffect:Clone()
				glow.Name = "Selection"
				glow.CFrame = currentblock.CFrame
				glow.Parent = currentblock.Parent
			elseif mouseraycast == currentblock then
				print("okay")
			end
		end
	end)
	
	--/ catch any errors so it doesnt stop our script
	if errormsg then
		warn(errormsg)	
	end
end

1 comment

0

if mouse.Target.Name ~= "part" then end

1 answer

Alright, for those who are googling to do this here it is:

I'm basically inserting the part into a table so that I can later check if the mouse is on that certain part

local currentblock

local table1 = {}


while wait() do
	local noerror,errormsg = pcall(function()
		local mouseraycast = mouse.Target
		
		--/ update list
		for i,v in pairs(table1) do
			if mouseraycast == v.Parent.Selection then
				
			else
				v.Parent.Selection:Destroy() 
				table.remove(table1,i)
			end
		end
		
		if mouseraycast then
			if mouseraycast.Parent.Parent == game.Workspace.SelectTest then
				if mouseraycast.Parent:FindFirstChild("Selection") == nil then
					currentblock = mouseraycast
					
					--/ clone our glow to the block
					local glow = replicatedstorage.MechanicEffects.SelectEffect:Clone()
					glow.Name = "Selection"
					glow.CFrame = currentblock.CFrame
					glow.Parent = currentblock.Parent
					
					table.insert(table1,currentblock)
					
				end
			end
		end
	end)
	
	--/ catch any errors so it doesnt stop our script
	if errormsg then
		warn(errormsg)	
	end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.