I an coding a lobby system and I want there to be text saying who created (joined first)
the lobby. When I try to set the text of owner to the player then the text “'s Lobby” then I get one of 2 errors depending on if I use player or player.Name. When I use player then i get the error “attempt to concatenate nil with string” but if I use player.Name then I get the error “attempt to index nil with Name.”
Here is my code:
local sgui = script.Parent.SurfaceGui
local owner = sgui.Owner
local requirement = sgui.Requirement
local status = sgui.Status
local publicity = sgui.Publicity
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player.Character and hit ~= player.Character.PrimaryPart then return end
if #plyrs == 0 then
owner.Text = player .. "'s Lobby"
else
local idx = table.find(plyrs, player)
if idx == nil then
table.insert(plyrs, player)
end
end
end)
Then I suspect this part of your check if causing the issue. This would mean that the player’s humanoid would need to touch the part, and not anything else.
Try replacing
if not (player and player.Character) or hit ~= player.Character.PrimaryPart then return end
with
if not (player and player.Character) then return end