Hello, I Want to use a different method to make a player only GUI because the methods I used before are long and take a lot of time to script, I tried making something like this and it did not work, It doesn’t work and nothing shows up in the output. Can someone help me with this? Thanks. (Local Script under ServerScriptService)
game.Players.PlayerAdded:Connect(function(player) --Notices when a player joins.
if player.Name == "TrackoTheTaco" then --Checks if the player who joined is allowed to access the GUI.
script.AdminGui.Parent = game.StarterGui --Shows the GUI to the allowed people who are in the game.
end
end)
You’re adding the GUI for everyone who joins the session after "TrackoTheTaco"(or you) joins the game. To access a player’s specific GUI, player.PlayerGui. It is an object generated per player and always is there.
game.Players.PlayerAdded:Connect(function(player) --Notices when a player joins.
if player.Name == "TrackoTheTaco" then --Checks if the player who joined is allowed to access the GUI.
script.AdminGui.Parent = player.PlayerGui --Shows the GUI to the allowed people who are in the game.
end
end)
Yes. However, you’re going to face an issue when writing…
player.Name == "TrackoTheTaco" or "Name2here"
It does not compare player.Name with Name2here. You have to write it again like this:
player.Name == "TrackoTheTaco" or player.Name == "Name2here"
On another security note, UserId should be a better alternative. Because if the user decides to change their username, their UserId remains the same but Name is changed.
Alright, For the sake of a test, I will use the username for now. I tried it and it did not work, Nothing was in the output when I tested it. Current Code:
game.Players.PlayerAdded:Connect(function(player) --Notices when a player joins.
if player.Name == "TrackoTheTaco" or player.Name == "Name2here" then --Checks if the player who joined is allowed to access the GUI.
script.AdminGui.Parent = player.PlayerGui --Shows the GUI to the allowed people who are in the game.
end
end)
One other thing to point out; you only have one instance of the admin script. So if you’re going to put it in playerGui you might also want to clone the instance so multiple admins can get it.
Oh, and outside this problem. The UI may be seen once and if the GUI resets somehow (e.g. ResetOnSpawn), it might be a problem. That’s for another topic though.