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)"

6 comments
I think that is working, but this part isn't working: 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?" The GUI isn't showing up on the owner's screen when someone touches the brick. Any ideas?
try doing print(game.Players:FindFirstChild(owner)) before that line, make sure you are getting the owner referenced correctly
Okay that helped a lot. I realized that once it ran once, the script stopped responding.
It never gets to the second if statement.
Nevermind. It works now! Thank you so much!
Np