Can someone help me with this script?
Alright, so I'm trying to make a script where someone touches a brick. The first person to touch it becomes the owner. Then any further users who touch it will cause a GUI to send to the owner asking if they can join their team. If the owner presses yes, it will teleport the user in, if not, then nothing will happen. Here are the scripts:
The first script:
02 | tpTo = Vector 3. new( 0 , 20 , 0 ) |
06 | script.Parent.Touched:connect( function (part) |
07 | if part.Parent:FindFirstChild( "Humanoid" ) then |
08 | local name = part.Parent.Name |
10 | if locked = = false then |
13 | part.Parent:MoveTo(tpTo) |
14 | print ( "Owner touched the brick" ) |
15 | else if locked = = true and name ~ = owner then |
16 | table.insert(_G.names, name) |
17 | game.Players [ owner ] .PlayerGui.AskGui.Frame.Visible = true |
18 | game.Players [ owner ] .PlayerGui.AskGui.User.Text = name.. " is asking to join your team. Accept this player?" |
And here is the localscript in the "Yes" button that the owner can press to accept a user:
1 | tpTo = Vector 3. new( 0 , 20 , 0 ) |
3 | game.Players [ _G.names [ #_G.names ] ] .Character:MoveTo(tpTo) |
4 | script.Parent.Parent.Visible = false |
6 | script.Parent.MouseButton 1 Down:connect(tp) |
I keep getting an error saying: "Players.Player1.PlayerGui.AskGui.Frame.Yes.LocalScript:3: attempt to get length of field 'names' (a nil value)"