So, I want a Text Label in my game to appear whenever I join the game. It would say “the owner has joined the game!!”.
But the problem is… the label is not appearing on the screen. I do not know exactly why it isn’t appearing.
I have tried changing “TextTransparency” to “Visible” and have true/false but that didn’t work. I am a beginning scripter so there is a high chance that I am missing something.
Here’s the script.
game.Players.PlayerAdded:Connect(function(plr)
if plr.UserId == 120905511 then
wait(5)
game.StarterGui.ScreenGui.TextLabel.TextTransparency = 0
wait(5)
game.StarterGui.ScreenGui.TextLabel.TextTransparency = 1
end
end)
You cannot access Gui’s through StarterGui, you should access it through PlayerGui.
local Client = game:GetService("Players").LocalPlayer
local PlayerGui = Client.PlayerGui
game.Players.PlayerAdded:Connect(function(plr)
if plr.UserId == 120905511 then
wait(5)
PlayerGui.ScreenGui.TextLabel.TextTransparency = 0
wait(5)
PlayerGui.ScreenGui.TextLabel.TextTransparency = 1
end
end)
Or, if you want to use Visible.
local Client = game:GetService("Players").LocalPlayer
local PlayerGui = Client.PlayerGui
game.Players.PlayerAdded:Connect(function(plr)
if plr.UserId == 120905511 then
wait(5)
PlayerGui.ScreenGui.TextLabel.Visible = true
wait(5)
PlayerGui.ScreenGui.TextLabel.Visible = false
end
end)
It is also coming back with an error “ServerScriptService.Script:2: attempt to index nil with ‘WaitForChild’”. Do I need to put the GUI in a different folder?
Its because the client/localplayer is meant to be used in a local script placed in the players startergui, starterplayerscripts, etc. But you’re placing it in serverscript service, which cant run localscripts or call for a localplayer
As @arbitiu stated, you can’t access a Client’s GUI from the server, and ideally you shouldn’t be messing with GUIs on the server anyways, the client is for visuals, and to an extent, sharing the computational load of the server for tasks that shouldn’t involve the server anyways.
local Players = 0
game.Players.PlayerAdded:Connect(function(plr)
if plr.UserId == 120905511 then
task.wait(5)
for _, Current in ipairs(game.Players:GetPlayers()) do
Current.PlayerGui.ScreenGui.TextLabel.TextTransparency = 0
task.wait(5)
Current.PlayerGui.ScreenGui.TextLabel.TextTransparency = 1
Players = Players + 1
if #game.Players:GetPlayers() == Players then
break
end
end
end
end)
print(tostring("Total: "..Players))
I’ve gone and looped through all the players, (probably the best way to do this), as well as made a little check, (not too needed). I hope this helped, if you have any questions regarding this thread, let me know!