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: Efficient Way

Previous Thread :: Next Thread 
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
05 Jun 2015 11:34 PM
What is an Efficient way to get a LocalPlayer from a regular script?
Report Abuse
LegitimatlyMe is not online. LegitimatlyMe
Joined: 30 Oct 2013
Total Posts: 1108
05 Jun 2015 11:36 PM
local plr = game.Players.(YOURNAMEHERE)













Let's see if you fall for it.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
05 Jun 2015 11:36 PM

There isn't any. Unless u know the player, then there is no point.

However, if you are using FilterEnabled (preferrably, not required), you can use RemoteEvents to send and recieve the player and whatever arguments you want to pass.
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
05 Jun 2015 11:40 PM
That makes very little sense in the context you provided.

Why do you want to get the LocalPlayer from a server-side script? What makes the LocalPlayer different from any other player?
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
05 Jun 2015 11:41 PM
for i,v in pairs(game.Players:GetChildren()) do
print(v.Name)
end

Bam. 2ez
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
05 Jun 2015 11:42 PM
@TimeTicks

Oh ho! You got me!
*sunglasses*
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
05 Jun 2015 11:46 PM
What I mean is, I need to find the LocalPlayer who touches the brick.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
05 Jun 2015 11:48 PM
script.Parent.Touched:connect(function(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if human then
local player = game.Players:GetPlayerFromCharacter(human.Parent)
print(player.Name)
end
end)
Report Abuse
amanda is not online. amanda
Joined: 21 Nov 2006
Total Posts: 5925
05 Jun 2015 11:49 PM
HAAAAAAAAAAAAAAFJSDIFRNGERG

--
local players = game:GetService("Players")
local part = script.Parent

part.Touched:connect(function(hit)
local character = hit.Parent
local player = players:GetPlayerFromCharacter(hit.Parent)
if player then
--code
end
end)
Report Abuse
Tokimonu is not online. Tokimonu
Joined: 18 Sep 2009
Total Posts: 643
05 Jun 2015 11:49 PM
i would do it like

game.Players.PlayerAdded:connect(function(plr)
print(plr.Name)
end)


then if you know how to script you could go on from there
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
05 Jun 2015 11:52 PM
The localplayer of a localscript is the player whos client the localscript is ran on. Since server-scripts run on the server and not any particular client, there is no localplayer.
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
05 Jun 2015 11:53 PM
Ok let me re-phrase what I said...sorry :(

I just need to figure out how to get the 'LocalPlayer' from when a player hits the textbutton. I can script it from there. (think of an if statement)
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
05 Jun 2015 11:55 PM
gui.MouseButton1Click:connect(function(player)
print(player.Name)
end)
Report Abuse
Tokimonu is not online. Tokimonu
Joined: 18 Sep 2009
Total Posts: 643
05 Jun 2015 11:56 PM
if it's a gui why not just use localscripts?
they're pretty
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
06 Jun 2015 12:01 AM
because the script has to be inside the button
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
06 Jun 2015 12:02 AM
@timeticks

error:

attempt to index local 'player'
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
06 Jun 2015 12:03 AM
oh i forgot mousebutton1click is stupid and doesnt allow that
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
06 Jun 2015 12:05 AM
>>I just need to figure out how to get the 'LocalPlayer' from when a player hits the textbutton.

I already explained to you, there isn't one in a normal script. You can, however, move up parent by parent to the player. Example:

Hierarchy:
Player
PlayerGui
ScreenGui
TextButton
Script

So you would do this to get the player:
local player = script.Parent.Parent.Parent.Parent


Although it is recommend you always use localscripts to handle guis and then if the server needs to handle some part of the gui, use a remoteevent or remotefunction to contact it.
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
06 Jun 2015 12:08 AM
TextButton? So it's a gui object.. Gui objects should be in PlayerGui anyways. So just use a localscript?
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
06 Jun 2015 12:11 AM
It's a surfacegui on a brick.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
06 Jun 2015 12:11 AM
local player = game.Players.LocalPlayer

Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
06 Jun 2015 12:12 AM
it's not a localscript...
Report Abuse
nQqzRYVpIKA5jLP is not online. nQqzRYVpIKA5jLP
Joined: 05 Mar 2015
Total Posts: 4135
06 Jun 2015 12:14 AM
You have to put the SurfaceGui in the Player's PlayerGui, then set the SurfaceGuis Adornee to the brick you would like it to display on. It is also advisable that you use a LocalScript rather than a server-script to reduce latency and unnecessary load on the server.
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
06 Jun 2015 12:25 AM
How can I set it "Adornee" to a block?
Report Abuse
Vritix is not online. Vritix
Joined: 01 Jan 2011
Total Posts: 2790
06 Jun 2015 12:31 AM
Let me re-phrase that... the 'Adornee' option is locked, how can I unlock it?
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