|
| 25 Apr 2014 12:17 PM |
I'm trying to make a small GUI box follow the cursor when it's hovering over a specific brick.
Here's the script so far:
coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer.Mouse coalgui = StarterGui.CoalGui
if game.Players.LocalPlayer.Mouse.Target == coal then mouseposition = Vector2.new(playermouse.X, playermouse.Y) coalgui.TextLabel.Visible = true
repeat coalgui.AbsolutePosition = mouseposition until game.Players.LocalPlayer.Mouse.Target ~= coal
wait() coalgui.TextLabel.Visible = false end |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:19 PM |
Why not just use the MouseEnter and MouseLeave events?
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
| |
|
|
| 25 Apr 2014 12:20 PM |
@sponge; That would require a SurfaceGui, and I felt this way was easier.
@rofl; The GUI doesn't even show up. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:24 PM |
@iOffensive Why not just create a SurfaceGui in the PlayerGui, then use a script that makes sure the mouse's target is coal, then sets the adornee to it and the face to the mouse's TargetSurface property, then make it do what you want with the MouseMoved event?
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 25 Apr 2014 12:25 PM |
You can't set the AbsolutePosition directly, apparently:
"This is a read-only property. It cannot be written to, only read." - wiki
Maybe you could try something with a billboard gui? Like settings it's adornee to the brick when the mouse is over it, and setting it to nil when it's not. |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 25 Apr 2014 12:25 PM |
| It's not just StarterGui; you need to say game.StarterGui |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:25 PM |
| I thought SurfaceGuis could only be placed in the 3D part of the game and not, for example, the PlayerGui. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:27 PM |
@smiley; Still doesn't work.
Script currently:
coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer.Mouse coalgui = StarterGui.CoalGui
if game.Players.LocalPlayer.Mouse.Target == coal then mouseposition = Vector2.new(playermouse.X, playermouse.Y) coalgui.TextLabel.Visible = true
repeat coalgui.AbsolutePosition = mouseposition until game.Players.LocalPlayer.Mouse.Target ~= coal
wait() coalgui.TextLabel.Visible = false end |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:27 PM |
@OP To make the SurfaceGui local, you can just put it in PlayerGui, then set it's adornee property.
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
2unknown2
|
  |
| Joined: 30 Oct 2011 |
| Total Posts: 9351 |
|
|
| 25 Apr 2014 12:28 PM |
Fixed Variables: coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer:GetMouse() coalgui = game.StarterGui.CoalGui |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:29 PM |
Eh, what is an adornee exactly?
I looked it up and it said "Sets the object in which to adorn to."
I looked up adorn's definition and it says to make more attractive, so I'm not sure what it means in lua |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:30 PM |
Did you get any errors @OP? If you didn't, make the coalgui variable the CoalGui inside the LocalPlayer's PlayerGui.
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:31 PM |
Adornee is basically the part that the GUI shows up on.
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:33 PM |
Here's the new script:
coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer:GetMouse() coalgui = game.Players.LocalPlayer.PlayerGui.CoalGui
if playermouse.Target == coal then mouseposition = Vector2.new(playermouse.X, playermouse.Y) coalgui.TextLabel.Visible = true
repeat coalgui.AbsolutePosition = mouseposition until game.Players.LocalPlayer.Mouse.Target ~= coal
wait() coalgui.TextLabel.Visible = false end
And it still doesn't work. |
|
|
| Report Abuse |
|
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 25 Apr 2014 12:37 PM |
| Tell us what the output is. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:39 PM |
Here is new script:
local player = game.Players.LocalPlayer coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer:GetMouse() coalgui = game.Players.LocalPlayer.PlayerGui.CoalGui local magnitude = (coal.Position - player.Position).magnitude
if playermouse.Target == coal and magnitude < 10 then mouseposition = Vector2.new(playermouse.X, playermouse.Y) coalgui.TextLabel.Visible = true
repeat coalgui.AbsolutePosition = mouseposition until game.Players.LocalPlayer.Mouse.Target ~= coal
wait() coalgui.TextLabel.Visible = false end
Output:
10:38:01.528 - local player = game.Players.LocalPlayer coal = Workspace.Co:3: attempt to index field 'LocalPlayer' (a nil value) 10:38:01.528 - Stack Begin 10:38:01.529 - Script 'local player = game.Players.LocalPlayer coal = Workspace.Co', Line 3 10:38:01.530 - Stack End |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:41 PM |
coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer:GetMouse() coalgui = game.Players.LocalPlayer.PlayerGui.CoalGui.Frame --Make sure you make a frame or something.
if playermouse.Target == coal then mouseposition = UDim2.new(0, playermouse.X, 0, playermouse.Y) coalgui.TextLabel.Visible = true
repeat coalgui.Position = mouseposition --Can't change AbsolutePosition of a GUI, so you need to use Position (which a ScreenGui doesn't have, read coalgui variable comment). until game.Players.LocalPlayer.Mouse.Target ~= coal
wait() coalgui.TextLabel.Visible = false end
Here's my siggy... Done. |
|
|
| Report Abuse |
|
|
|
| 25 Apr 2014 12:47 PM |
New script:
coal = Workspace.Coal.SurfaceGUIHolder playermouse = game.Players.LocalPlayer:GetMouse() coalgui = game.Players.LocalPlayer.PlayerGui.CoalGui.Frame
if playermouse.Target == coal then mouseposition = UDim2.new(0, playermouse.X, 0, playermouse.Y) coalgui.Visible = true coalgui.TextLabel.Visible = true
repeat coalgui.Position = mouseposition until game.Players.LocalPlayer.Mouse.Target ~= coal
wait() coalgui.Visible = false coalgui.TextLabel.Visible = false end
Output is still the same |
|
|
| Report Abuse |
|
|
| |
|
| |
|
smiley599
|
  |
| Joined: 23 Jan 2010 |
| Total Posts: 21869 |
|
|
| 25 Apr 2014 01:39 PM |
| It is in a LocalScript in StarterGui right? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 25 Apr 2014 02:05 PM |
Changed a couple things. Here's new script:
repeat wait() until game.Players.LocalPlayer.PlayerGui local player = game.Players.LocalPlayer coal = Workspace.Coal.SurfaceGUIHolder local playermouse = player:GetMouse() coalgui = game.Players.LocalPlayer.PlayerGui.CoalGui coalguiframe = game.Players.LocalPlayer.PlayerGui.CoalGui.Frame
if playermouse.Target == coal then mouseposition = UDim2.new(0,playermouse.X, 0,playermouse.Y) coalguiframe.Visible = true coalgui.TextLabel.Visible = true
repeat coalguiframe:TweenPosition(mouseposition, InOut, Linear, 0.02) until playermouse.Target ~= coal
wait() coalgui.Visible = false coalgui.TextLabel.Visible = false end |
|
|
| Report Abuse |
|
|