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

Issues with Mouse.Target, help?

when I click the baseplate, it just prints the name of the brick but won't print "ITS BASE" but when I click a non object(nil) it prints "LOL NAAA"..

player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Down:connect(function(click)
	print(mouse.Target)
	
	if mouse.Target == "BasePlate" then
		print("ITS BASE!")
	elseif mouse.Target == nil then
		print("LOL NAAA")
	end
end)

2 answers

✓ Accepted answer
player = game.Players.LocalPlayer
mouse = player:GetMouse()

mouse.Button1Down:connect(function(click)
    print(mouse.Target)

    if mouse.Target and mouse.Target.Name == "BasePlate" then --Check if the name of the target is BasePlate
        print("ITS BASE!")
    elseif mouse.Target == nil then
        print("LOL NAAA")
    end
end)

2 comments

0

Wow, Thanks, I did mouse.Target.Name == "BasePlate" then - but it didnt work and was giving me this weird error. Thanks again bud!

1

Because if Mouse.Target is nil it would error.

You forgot to check its name You were just checking if the object was a BasePlate.

player = game.Players.LocalPlayer
mouse = player:GetMouse()
mouse.Button1Down:connect(function(click)
	if mouse.Target~=nil then --Check to make sure it wont break
		if mouse.Target.Name == "BasePlate" then --Needs to check its name
			print("ITS BASE!")
		elseif mouse.Target == nil then
			print("LOL NAAA")
		end
	end 
end)

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