|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 03 Dec 2008 |
| Total Posts: 2479 |
|
|
| 15 Sep 2015 08:02 PM |
| That's probably the simplest form. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 15 Sep 2015 08:05 PM |
| Also I suggest just game.Players.LocalPlayer, no .Name because it already gives you the name. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 15 Sep 2015 08:20 PM |
| Oh didn't see the +5 sorry |
|
|
| Report Abuse |
|
|
|
| 15 Sep 2015 08:23 PM |
Alright. Thanks!
~MightyDantheman |
|
|
| Report Abuse |
|
|