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

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

Asked by 8 years ago

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!

0
This is so hard to read oml. Check the answer below, pretty sure its correct. joalars2 107 — 8y

1 answer

Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
8 years ago

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)
0
Thanks for the help man, it's working now. TimothyWellesley 10 — 8y
0
No problem Shawnyg 4330 — 8y
Ad

Answer this question