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

Help using mouse.Target?

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

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.

1 comment

0

Thanks! Your smart xD

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