generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Script Doesn't Work

Previous Thread :: Next Thread 
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
25 Apr 2014 12:19 PM
Why not just use the MouseEnter and MouseLeave events?

Here's my siggy... Done.
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
25 Apr 2014 12:19 PM
What's wrong with it?
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
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 is not online. 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 is not online. 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
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
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 is not online. 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
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
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
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
25 Apr 2014 12:31 PM
Adornee is basically the part that the GUI shows up on.

Here's my siggy... Done.
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
25 Apr 2014 12:37 PM
Tell us what the output is.
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
Spongocardo is not online. Spongocardo
Joined: 06 Sep 2008
Total Posts: 2843
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
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
25 Apr 2014 01:15 PM
B1
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
25 Apr 2014 01:35 PM
B2
Report Abuse
smiley599 is not online. smiley599
Joined: 23 Jan 2010
Total Posts: 21869
25 Apr 2014 01:39 PM
It is in a LocalScript in StarterGui right?
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
25 Apr 2014 01:39 PM
Yes
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
25 Apr 2014 01:50 PM
B2
Report Abuse
iOffensive is not online. iOffensive
Joined: 13 Jun 2013
Total Posts: 416
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image