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

How to set a screengui to show when a mouse hovers over a brick if character is <= to 10 studs away?

I'm trying to make a screengui show up when your mouse hovers over a brick, which I have actually got to work. My problem though comes when I try to set it to work at a distance of 10 studs or less.

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

if (torso.Position - game.Workspace.Part1.Position).magnitude <11 then
mouse.Move:connect(function()
if mouse.Target and mouse.Target == game.Workspace.Part1 then
player.PlayerGui.SpecialHoverGUI.Frame.Visible = true
else 
player.PlayerGui.SpecialHoverGUI.Frame.Visible = false

end
end)

I can't for the life of me understand what's going wrong. (I am a novice scripter which would probably explain a lot). Please help!

1 comment

0

This is so hard to read oml. Check the answer below, pretty sure its correct.

1 answer

✓ Accepted answer

Nice try. The only thing I see wrong, is that you need to move your first if statement down a bit, since it doesn't constantly check if you're within range!

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

mouse.Move:connect(function()
	if mouse.Target and mouse.Target == game.Workspace.Part1 and (player.Character.Torso.Position - game.Workspace.Part1.Position).magnitude <11  then -- Move the if statement down here, so whenever the mouse moves, it can check the range!
		player.PlayerGui.SpecialHoverGUI.Frame.Visible = true
	else 
		player.PlayerGui.SpecialHoverGUI.Frame.Visible = false
	end
end)

2 comments

0

Thanks for the help man, it's working now.

0

No problem

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