mouse.Target() Breaks when hover over air

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to be able to hover the mouse over blocks and the sky without the script breaking,

  2. What is the issue? Include screenshots / videos if possible!
    it always breaks when i hover over the sky.

local blockch = tostring(Block_Choice)
	script.Parent.Name = blockch
	if mouse.Target:FindFirstChild("Creator") then
		GUI.CurrentBlock.Block.Made.Text = "Made by " .. mouse.Target.Creator.Value
	end
	if not mouse.Target:FindFirstChild("Creator") then
		--not exists
	end

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using if statements and nothing has helped.

Here is the inside of each part that someone places.
image
By the way this is a building system.
Here is the error:

1 Like

Add an if statement to check if target is nil or not.

if mouse.Target ~= nil then 
	if mouse.Target:FindFirstChild("Creator") then
		GUI.CurrentBlock.Block.Made.Text = "Made by " .. mouse.Target.Creator.Value
	end
	if not mouse.Target:FindFirstChild("Creator") then
		--not exists
	end
end
1 Like

Thank you so much, it works now!

1 Like