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: Finding Player Who Clicked? (Help plz)

Previous Thread :: Next Thread 
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 07:50 PM
How would I find the player who clicked the gui in this script:

function onClicked()
script.Parent.Parent:Destroy()
end
script.Parent.MouseButton1Click:connect(onClicked)

-----

Also, would this have to be in a local script?

~MightyDantheman
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
15 Sep 2015 07:54 PM
Yes, a localscript. There are no parameters for the MouseButton1Click event. In a local script, you can always put

player = game.Players.LocalPlayer to get the player interacting with the GUI.
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:01 PM
Thanks! Also, is there an easier way or more efficient way to find the character in the workspace? This is how I did it, but I feel like there is a better way:

function onClicked()
local playerFind = game.Players.LocalPlayer.Name
local player = game.Workspace:FindFirstChild(playerFind)
player:Destroy()
end
script.Parent.MouseButton1Click:connect(onClicked)

-----

~MightyDantheman
Report Abuse
Raphael7 is not online. Raphael7
Joined: 03 Dec 2008
Total Posts: 2479
15 Sep 2015 08:02 PM
That's probably the simplest form.
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
15 Sep 2015 08:04 PM
local player = game.Players.LocalPlayer
repeat wait() until player.Character -- waits until the character is loaded
local char = player.Character

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

http://wiki.roblox.com/index.php?title=Character
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
15 Sep 2015 08:05 PM
Also I suggest just game.Players.LocalPlayer, no .Name because it already gives you the name.
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:06 PM
Also, how come this won't work (using the last scrip):

function onClicked()
local playerFind = game.Players.LocalPlayer.Name
local player = game.Workspace:FindFirstChild(playerFind)
local playerPos = player.Position
player.Vector3.new(playerPos.x, playerPos.y + 5, playerPos.z)
end
script.Parent.MouseButton1Click:connect(onClicked)

-----

~MightyDantheman
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:07 PM
Okay.

~MightyDantheman
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
15 Sep 2015 08:10 PM
local playerPos = player.Position
player.Vector3.new(playerPos.x, playerPos.y + 5, playerPos.z)
end

You're trying to set the player's position to the player's position?
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:16 PM
Trying to teleport the character up from it's current position. Though, I don't really need this script (this is just for learning purposes). How would I teleport the player to a current location (x,y,z)?

~MightyDantheman
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:17 PM
I meant, any location with z,y,z. I don't know why I said "current".

~MightyDantheman
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:20 PM
This script doesn't do what I want, either:

function onClicked()
local playerFind = game.Players.LocalPlayer.Name
local player = game.Workspace:FindFirstChild(playerFind)
player.Position = Vector3.new(0,10,0)
end
script.Parent.MouseButton1Click:connect(onClicked)

-----

~MightyDantheman
Report Abuse
LongKillKreations is not online. LongKillKreations
Joined: 14 Feb 2014
Total Posts: 4502
15 Sep 2015 08:20 PM
local player = game.Players.LocalPlayer;
local character = player.Character or player.CharacterAdded:wait();
local torso = character:WaitForChild("Torso")

script.Parent.MouseButton1Click:connect(function()
local pos = torso.Position
torso.CFrame = CFrame.new(pos.X, pos.Y + 5, pos.Z)
end)
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
15 Sep 2015 08:20 PM
Oh didn't see the +5 sorry
Report Abuse
MightyDantheman is not online. MightyDantheman
Joined: 06 May 2011
Total Posts: 5108
15 Sep 2015 08:23 PM
Alright. Thanks!

~MightyDantheman
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