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

How do i remove the error when i target the skybox?

code:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local npcs = game.Workspace.Npc
local debounce = false


mouse.Button1Down:connect(function()
	if mouse.Target.Parent.Parent == npcs then
		print("d a b")
	end
end)

while true do
  wait()
	 if not debounce then
		if mouse.Target.Parent.Parent == npcs then
			local selec = mouse.Target.Parent:WaitForChild("SelectionBox")
			local subject = mouse.Target.Parent.Parent
			
			selec.Adornee = mouse.Target.Parent
			
		else
		 if mouse.Target == nil then end
			if mouse.Target.Parent.Parent ~= npcs then	
				for i,v in pairs(game.Workspace.Npc:GetChildren()) do
					if v:IsA("Model") then
						for i,a in pairs(v:GetChildren()) do
							if a:IsA("SelectionBox") then
								a.Adornee = nil
								
							end
						end
					end
				end	
			end
		end
	end
	wait()
	debounce = false
end

sorry if its messy ;-;

1 answer

✓ Accepted answer

You can simply check if the target exists with an if statement. If it does not exist, then your code will be stopped and the error won't occur.

-- define the mouse
if mouse.Target then -- Target exists.  Let your code continue.
	
end

1 comment

0

oh l0l

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