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

Help using mouse.Target?

Asked by
Mr1Vgy 30
10 years ago

Here is my script, I'm trying to make it so that if the players mouse hovers over a brick, a Gui appears, but it doesn't seem to be working... Can anyone help me?

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

if mouse.Target:FindFirstChild("ATM")then
    script.Parent.Visible = true
end

1 answer

Log in to vote
1
Answered by
DataStore 530 Moderation Voter
10 years ago

Currently your script is running once meaning that the condition of the if statement would need to be true at the time of the script running for anything to occur. The below should work for what you need, though it could probably be done better.

local Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.Move:connect(function() 
    local Target = Mouse.Target
    if Target == nil then return end
    if Target.Parent.Name == "ATM" then --// Checking whether the mouse's targeted item's parent's name is ATM. If so, change the script's parent's Visible property. 
        script.Parent.Visible = true
    else --// Otherwise, make it invisible. 
        script.Parent.Visible = false
    end
end)

Move is an event which is fired whenever the mouse is moved.

0
Thanks! Your smart xD Mr1Vgy 30 — 10y
Ad

Answer this question