Still have questions? Join our Discord server and get real time help.
4

# Making a Gui Visible when you hover over another players character?

What methods should I use if you hover your mouse over another players torso and it brings up a Gui at the mouse position?

Should I use OnMouseHover? I'm not really sure how to make the gui appear at the position of the mouse when they hover either? Can anyone go in depth on how to do this?

My main question is, how would I make a Gui be at the mouse position and only be activated/visible when it hovers over another players torso?

Here is my attempt

Attempt

wait()
local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local Frame = script.Parent.Tag
local Content = script.Parent:WaitForChild("Content")

mouse.Move:connect(function()
local X, Y = mouse.X, mouse.Y
if game.Players:GetPlayerFromCharacter(mouse.Target.Parent)-- Checks to make sure they are an actual player
and X > script.Parent.AbsolutePosition.x and
Y > script.Parent.AbsolutePosition.y and
X < script.Parent.AbsolutePosition.x+script.Parent.AbsoluteSize.x and
Y < script.Parent.AbsolutePosition.y+script.Parent.AbsoluteSize.y
then

Frame.Visible = true; -- Change frame to whatever you want visible
Frame.Position = UDim2.new(0,X+1,0,Y+1)
else

Frame.Visible = false; -- Change frame to whatever you want invisible

end

end)



Error: Target comes up as a nil value.

3
Aethex 255
6 years ago

As a LocalScript inside of the GUI, you would use the Move event to check when the mouse is moved and you would get the mouse's target (mouse variable.Target) to get the target the mouse is at. You would then check if it was a player and make the GUI visible if so.

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

mouse.Move:connect(function()

if game.Players:GetPlayerFromCharacter(mouse.Target.Parent) then -- Checks to make sure they are an actual player

script.Parent.Frame.Visible = true; -- Change frame to whatever you want visible

else

script.Parent.Frame.Visible = false; -- Change frame to whatever you want invisible

end

end)


local plr = game.Players.LocalPlayer;
local mouse = plr:GetMouse();
local Frame = script.Parent.Tag;
local Content = script.Parent:WaitForChild("Content");

mouse.Move:connect(function()

local X, Y = mouse.X, mouse.Y;

if mouse.Target then

if game.Players:GetPlayerFromCharacter(mouse.Target.Parent)-- Checks to make sure they are an actual player
and X > script.Parent.AbsolutePosition.x and
Y > script.Parent.AbsolutePosition.y and
X < script.Parent.AbsolutePosition.x+script.Parent.AbsoluteSize.x and
Y < script.Parent.AbsolutePosition.y+script.Parent.AbsoluteSize.y
then

Frame.Visible = true; -- Change frame to whatever you want visible
Frame.Position = UDim2.new(0,X+1,0,Y+1);

else

Frame.Visible = false; -- Change frame to whatever you want invisible

end

else

Frame.Visible = false;

end

end)


My apologies, for I forgot to actually check if there was a target. Please let me know of any other concerns you may have.

0
I'm a little confused on (mouse.Target.Parent) What would the target be and what would the Parent be? IntellectualBeing 430 — 6y
0
This is what I tried, check my edit in the question. IntellectualBeing 430 — 6y
0
Target comes up as a nil value. IntellectualBeing 430 — 6y
0
I edited it to fit your needs. Please let me know of any other problems it may have. Aethex 255 — 6y