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

MouseIcon - When mouse's target is the door mouse icon doesn't display?

What I want is when the mouse hovers over the door, an image label is visible at the mouse.

--//Main
game:GetService("RunService").RenderStepped:connect(function()
	local X = Mouse.X -- mouse x axis
	local Y = Mouse.Y -- mouse y axis
	
	if Mouse.Target then
		if Mouse.Target.Name == "Door1" or "Door2" or "Door3" or "Door4" then
			print("Mouse has closet as target")
			hover.Visible = true
			hover.Position = UDim2.new(0, X -50, 0, Y-50)
		else
			hover.Visible = false
		end
	end
end)

The code does not work. It only works when I set Mouse.Target.Name to only one name (ex. "Door1"). But when I use "Door1" or "Door2" or ....., it never works. Why is that?

1 answer

✓ Accepted answer
game:GetService("RunService").RenderStepped:connect(function()
    local X = Mouse.X -- mouse x axis
    local Y = Mouse.Y -- mouse y axis

    if Mouse.Target then
        if Mouse.Target.Name == "Door1" or Mouse.Target.Name == "Door2" or Mouse.Target.Name == "Door3" or Mouse.Target.Name == "Door3" then
            print("Mouse has closet as target")
            hover.Visible = true
            hover.Position = UDim2.new(0, X -50, 0, Y-50)
        else
            hover.Visible = false
        end
    end
end)

The initial script wouldn't work because three of the expressions are just strings, and not conditional.

1 comment

0

Wow. I totally forgot about conditionals and strings. Thanks :)

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