There are a couple of issues with this, most of them just being things that could be done better.
Firstly, the problem causing your script not to work, is that the ScreenGui you are relying on is not inside the PlayerGui right as the PlayerGui is added. This can be fixed by changing v:WaitForChild("PlayerGui").PlayerEntered.Frame to v:WaitForChild("PlayerGui"):WaitForChild("PlayerEntered") :WaitForChild("Frame")
Secondly, you seem to be relying on an existing ScreenGui here, while it might be easier to create a new ScreenGui from scratch in the script in this case.
Thirdly, you shouldn't put a copy of the GUI in the StarterGui.
Fourthly, using the findGui function you declared like that is pointless, confusing and counterintuitive. Take it out.
Fifthly, you currently only destroy one of the 'chat' TextLabels after three seconds rather than all of them.
Sixthly, it's probably more efficient to create a prototype for the TextLabel beforehand and just clone it later after changing the text appropriately.
Sevently, your script currently also tries to insert the TextLabel into the player which just joined, and telling them they just joined seems a bit redundant since they are aware of that themself.
Lastly, it's better to use game.Players:GetPlayers() than game.Players:GetChildren() if you want to loop through all the players.
Putting all of this together, this is the solution:
playerEnteredLabelProto = Instance.new("TextLabel")
playerEnteredLabelProto.Name = "Button"
playerEnteredLabelProto.Size = UDim2.new(0,300,0,40)
playerEnteredLabelProto.Position = UDim2.new(0,10,0,205)
playerEnteredLabelProto.Font = "ArialBold"
playerEnteredLabelProto.FontSize = "Size18"
playerEnteredLabelProto.BackgroundColor3 = Color3.new(170/255,170/255,127/255)
playerEnteredLabelProto.BorderColor3 = Color3.new(0/255,0/255,0/255)
playerEnteredLabelProto.BorderSizePixel = 2
playerEnteredLabelProto.TextColor3 = Color3.new(0/255,0/255,0/255)
playerEnteredLabelProto.TextStrokeColor3 = Color3.new(255/255,170/255,0/255)
playerEnteredLabelProto.TextStrokeTransparency = 0.5
playerEnteredLabelProto.BackgroundTransparency = 0.3
game:GetService("Players").PlayerAdded:connect(function(newPlayer)
playerEnteredLabelProto.Text = newPlayer.Name .. " joined the game."
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
if player ~= newPlayer then
local playerGui = player:FindFirstChild("PlayerGui")
if playerGui then
local screenGui = Instance.new("ScreenGui", playerGui)
playerEnteredLabelProto:Clone().Parent = screenGui
Delay(3, function()
screenGui:Destroy()
end)
end
end
end
end)
1 comment
Just make a GUI, put it in StarterGui, Done :D