Yep, it is possible. I recommend putting it all in the same LocalScript, in StarterGui.
In this answer, I'm assuming you already have both GUI's created, and they look like this, and OnHoverGui.MainFrame.Visible
is false
.
First, define the LocalPlayer, the GUI's, and wait for them to load.
1 | local plr = game:GetService( 'Players' ).LocalPlayer |
2 | local PlayerGui = game:GetService( 'Players' ).LocalPlayer:WaitForChild( 'PlayerGui' ) |
3 | local InputGui = PlayerGui:WaitForChild( 'MsgInputGui' ) |
4 | local OnHoverGui = PlayerGui:WaitForChild( 'OnHoverGui' ) |
Then, you might want to define some variables for the Frames, TextBoxes and TextLabels, so it's easier to manipulate them.
1 | local InputFrame = InputGui:WaitForChild( 'MainFrame' ) |
2 | local OnHoverFrame = OnHoverGui:WaitForChild( 'MainFrame' ) |
3 | local InputBox = InputFrame:WaitForChild( 'InputBox' ) |
4 | local MsgLabel = OnHoverFrame:WaitForChild( 'MsgLabel' ) |
Afterwards, set up the anonymous function that'll handle the supposed "OnHover" event. Since you'd have to put ClickDetectors in all of the parts in all characters to use OnHover
, let's use the Move
event of the Player's mouse.
01 | plr:GetMouse().Move:connect( function () |
03 | local Target = plr:GetMouse().Target |
05 | if Target = = nil then OnHoverFrame.Visible = false ; return end |
07 | if Target.Parent = = workspace then OnHoverFrame.Visible = false ; return end |
09 | local TargetPlayer = game:GetService( 'Players' ):GetPlayerFromCharacter(Target.Parent) |
11 | if TargetPlayer = = nil then OnHoverFrame.Visible = false ; return end |
13 | local TargetPlayersMessage = TargetPlayer:WaitForChild( 'PlayerGui' ):WaitForChild( 'MsgInputGui' ):WaitForChild( 'MainFrame' ):WaitForChild( 'InputBox' ).Text |
15 | MsgLabel.Text = TargetPlayersMessage |
17 | OnHoverFrame.Visible = true |
And done! Final script:
01 | local plr = game:GetService( 'Players' ).LocalPlayer |
02 | local PlayerGui = game:GetService( 'Players' ).LocalPlayer:WaitForChild( 'PlayerGui' ) |
03 | local InputGui = PlayerGui:WaitForChild( 'MsgInputGui' ) |
04 | local OnHoverGui = PlayerGui:WaitForChild( 'OnHoverGui' ) |
06 | local InputFrame = InputGui:WaitForChild( 'MainFrame' ) |
07 | local OnHoverFrame = OnHoverGui:WaitForChild( 'MainFrame' ) |
08 | local InputBox = InputFrame:WaitForChild( 'InputBox' ) |
09 | local MsgLabel = OnHoverFrame:WaitForChild( 'MsgLabel' ) |
11 | plr:GetMouse().Move:connect( function () |
13 | local Target = plr:GetMouse().Target |
15 | if Target = = nil then OnHoverFrame.Visible = false ; return end |
17 | if Target.Parent = = workspace then OnHoverFrame.Visible = false ; return end |
19 | local TargetPlayer = game:GetService( 'Players' ):GetPlayerFromCharacter(Target.Parent) |
21 | if TargetPlayer = = nil then OnHoverFrame.Visible = false ; return end |
23 | local TargetPlayersMessage = TargetPlayer:WaitForChild( 'PlayerGui' ):WaitForChild( 'MsgInputGui' ):WaitForChild( 'MainFrame' ):WaitForChild( 'InputBox' ).Text |
25 | MsgLabel.Text = TargetPlayersMessage |
27 | OnHoverFrame.Visible = true |
Hope it helps! :)
If it doesn't work, or you don't understand something, please comment, and I'll do my best to fix it/explain.