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 » Scripters
Home Search
 

Re: Scripting with distance help!

Previous Thread :: Next Thread 
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 05:34 PM
Hi, I'm trying to make a billboard GUI that only appears when the player is within a certain distance, and I'm unsure of what variable to use for it, I thought it was "MaxDistanceFromPlayer" or something, but I'm not sure of how to do it. I thought it would be something like this.

while true do
if MaxDistanceFromPlayer < 50 then
game.Workspace.Thing.TinyThing.BillBoardGUI.TextBox.Visible = true
end
end

But I'm not sure.
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 05:38 PM
It's DistanceFromCharacter and if you wanna do an infinite loop at-least use a wait().

http://wiki.roblox.com/index.php?title=API:Class/Player/DistanceFromCharacter

Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 05:55 PM
I'm trying to mess with it, but I'm still not exactly getting what I want.


while true do
if game.Workspace.Campfire.Part.Position.X.DistanceFromPlayer < 50 then
game.Workspace.Campfire.Part.BillboardGui.TextBox.Visible = true
wait()
end
end
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 06:03 PM
Don't hav time to read it in csgo game but its :DistanceFromPlayer not .DistanceFromPlayer
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 06:19 PM
bumped
Report Abuse
doggy00 is online. doggy00
Joined: 11 Jan 2011
Total Posts: 3571
18 Nov 2016 06:29 PM
--you'd need to put this in a local script

player = game.Players.LocalPlayer
name = player.Name

while true do
wait()
char = workspace:WaitForChild(name)
if player.Character ~= nil then --just in case someone in the game is named after something in workspace
torso = player.Character:WaitForChild("Torso")
local magnitude = (workspace.Thing.TinyThing.Position - torso.Position).magnitude
if magnitude < 50 then
game.Workspace.Thing.TinyThing.BillBoardGUI.TextBox.Visible = true
end
end
end

--i know this is really sloppy, i'm a sloppy scripter, but this should work
Report Abuse
doggy00 is online. doggy00
Joined: 11 Jan 2011
Total Posts: 3571
18 Nov 2016 06:30 PM
oh, and of course make it invisible again if the magnitude is greater than/equal to 50.
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 06:51 PM
ok now that I've finished my game and owned some newbs i can explain the method that i gave you.

So what you're doing whether you use the other guys code or not will only work on a server with 1 player on and I'm not sure if that's what you want. Doing what the other guy did (assuming its correct) using the method i gave you will go something like this:

part = game.Workspace.Thing

while wait() do

for _, player in pairs(game.Players:GetPlayers()) do
if player:DistanceFromCharacter(part.Position) <= 50 then
game.Workspace.Thing.TinyThing.BillBoardGUI.Enabled = true

else
game.Workspace.Thing.TinyThing.BillBoardGUI.Enabled = false

end
end
end


To make it work with multiple people on the server you would have to put the gui in StarterGui and set its Adornee property to the part 'thing' then you would use this code:

part = game.Workspace.Thing

while wait() do

for _, player in pairs(game.Players:GetPlayers()) do
if player:DistanceFromCharacter(part.Position) <= 50 then
player.PlayerGui.BillboardGui.Enabled = true
else
player.PlayerGui.BillboardGui.Enabled = false
end
end
end

I am assuming that 'Thing' is a part in workspace and not a model name so change it if you need to and I'm sure you can figure out the rest.
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 07:07 PM
Ok, so I made a local script and pasted the multiple people thing into it, but it still isn't really doing anything, I did the rest of the steps correctly though.
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 07:14 PM
It works fine for me so tell me what is going wrong, what errors come up in the console, where you have put the script and gui and if you are testing it using a test server or not
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 07:17 PM
OK, So its in workspace. And one error comes up when run through Output: 18:16:12.401 - BillboardGui is not a valid member of PlayerGui, and this is in studio.

1 more thing, the "Thing" is a model, its actually a campfire that I made.
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 07:22 PM
Change part = game.Workspace.Thing to part = game.Workspace.Thing.TinyThingy

move the billboard Gui to StarterGui and set the Adornee property to the TinyThingy part.
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 07:27 PM
I've done that, and still does not work sadly. Sorry if this is getting difficult.
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 07:28 PM
Is the script supposed to be in the BillboardGUI or somewhere else?
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 07:28 PM
nvm use this:

for _, player in pairs(game.Players:GetPlayers()) do
if player:DistanceFromCharacter(part.Position) <= 50 then
player.PlayerGui.BillboardGUI.Enabled = true
else
player.PlayerGui.BillboardGUI.Enabled = false
end
end
end
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 07:29 PM
honestly i think it can be anywhere tbh. I put it in ServerScriptService first then moved it in a localscript to playergui then moved it again inside the BillboardGui
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 07:33 PM
Output still says BillboardGUI is not a valid member of PlayerGUI. :|
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 07:35 PM
lol try this:

part = game.Workspace.Thing.TinyThingy

for _, player in pairs(game.Players:GetPlayers()) do
if player:DistanceFromCharacter(part.Position) <= 50 then
player.PlayerGui.BillBoardGUI.Enabled = true
else
player.PlayerGui.BillBoardGUI.Enabled = false
end
end
end
Report Abuse
Pataponuberness is online. Pataponuberness
Joined: 06 Aug 2011
Total Posts: 446
18 Nov 2016 07:46 PM
Eureka! It worked! Thanks so much for the help! :)
Report Abuse
enzotinman1 is not online. enzotinman1
Joined: 22 Jun 2012
Total Posts: 408
18 Nov 2016 07:54 PM
awesome, np.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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