I need a button that teleports player when clicked but the output says "attempt to index nil with parent" pls help
local tp = script.Parent tp.MouseButton1Click:Connect(function(go) local TeleportService = game:GetService("TeleportService") local lobby = 4920256514 local player = game.Players:GetPlayerFromCharacter(go.Parent) if player then TeleportService:Teleport(lobby, player) end end)
Try putting this in a LocalScript
local tp = script.Parent local TeleportService = game:GetService("TeleportService") tp.MouseButton1Click:Connect(function() local lobby = 4920256514 TeleportService:Teleport(lobby) end end)
The player will default to LocalPlayer in a LocalScript
There is two errors I can see, first is that you reference the player that joined the game and your trying to index something that is nil on line 6.
local player = game:GetService( "Players").LocalPlayer local tp = script.Parent local lobby = 4920256514 local TeleportService = game:GetService("TeleportService") tp.MouseButton1Click:Connect(function(go) if game.Players:GetPlayerFromCharacter(go) then if player then TeleportService:Teleport(lobby) end end end