Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago
Edited 6 years ago
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.

0
Wow. I totally forgot about conditionals and strings. Thanks :) Florian27 76 — 6y
Ad

Answer this question