Haven't tested it, but the errors most likely occur because of several things:
- The first error is a comparison error in the following line:
if player.Name == "0mrlight0" or "edward538" then
This happens because you're comparing "player.Name" to a string value, but it won't be able to process the latter comparison. To fix this, we need to add another "player.Name" to the latter option to get the following code:
if player.Name == "0mrlight0" or player.Name == "edward538" then
To note, it is typically better to use "player.UserId", as opposed to "player.Name", just because of the recent name changes.
- The second error is a pretty common one; in the client, we use the StarterGui, but on the server, all of the children of StarterGui will pull over to the "PlayerGui", which can only be seen by the local player. To fix this, we need to direct it to its playergui:
player.PlayerGui.Frame.ScreenGui.Button.Visible = true
- The third error is not an error per se; rather, we should wait for the character, because after we wait for the character, we should be able to access the PlayerGui. This happens because the player or game typically loads before all of the PlayerGui's load, which is why we sometimes see the unloaded decals. There are two ways to fix this; it is recommended, however, that we use the CharacterAdded event to wait until the character is loaded, like so:
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function()
if player.Name == "0mrlight0" or player.Name == "edward538" then
player.PlayerGui.Frame.ScreenGui.Button.Visible = true
end
end)
end)
We waited for the character, so that all of the gui's are loaded, and we are able to access it. The reason why it didn't work was because you're trying to address it before it is finished loading, which means that it technically isn't there, which results in an error.
The second method is to use a ":WaitForChild("")" event to wait for all of the assets within it to load. This can be done, like so:
game.Players.PlayerAdded:connect(function(player)
if player.Name == "0mrlight0" or player.Name == "edward538" then
player:WaitForChild("PlayerGui"):WaitForChild("Frame"):WaitForChild("ScreenGui"):WaitForChild("Button").Visible = true
end
end)
Once again, I haven't tested it, but it should work, from memory. If it did, feel free to accept it! If it didn't, let me know, and I'll try to fix it.
1 comment
In practice, it is generally recommended to use the player's userId because it will always return the same account.