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:
locked = false tpTo = Vector3.new(0, 20, 0) owner = "" _G.names = {""} script.Parent.Touched:connect(function(part) if part.Parent:FindFirstChild("Humanoid") then local name = part.Parent.Name if locked == false then owner = name locked = true part.Parent:MoveTo(tpTo) -- TELEPORT print("Owner touched the brick") else if locked == true and name ~= owner then table.insert(_G.names, name) game.Players[owner].PlayerGui.AskGui.Frame.Visible = true game.Players[owner].PlayerGui.AskGui.User.Text = name.." is asking to join your team. Accept this player?" end end end end)
And here is the localscript in the "Yes" button that the owner can press to accept a user:
tpTo = Vector3.new(0, 20, 0) function tp() game.Players[_G.names[#_G.names]].Character:MoveTo(tpTo) script.Parent.Parent.Visible = false end script.Parent.MouseButton1Down: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)"
You need to use a for loop to cycle through the players, your treating the players like its a single object, but its in reality an array or table of objects, example below.
for i = 1, #_G.names do game.Players:FindFirstChild( _G.names[i]).Character:MoveTo(tpTo) end
This should work, mark correct if so, but if its wrong please let me know. I may have messed up global variables a bit so let me know if so, but this should be the basic concept you would want to use for line three in the local script named Yes.