Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Gui not changing, and script not defining a player?

Asked by 8 years ago

Trying to make an 'Admin Gui'. In scriptserverservice I have a script that does this:

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "0mrlight0" or "edward538" then
        game.StarterGui.Frame.ScreenGui.Button.Visible = true
    end
end)

This dosen't work, it makes the button visible for everyone. The script inside the button does this:

--VARIBLE LIST
MM1 = script.Parent.Parent.MM1
Button = script.Parent
Button.MouseButton1Down:connect(function()
    Button.Visible = false
    MM1.Visible = true

end)

When I click the button it doesn't hide or make the next gui show up. Any help?

0
In practice, it is generally recommended to use the player's userId because it will always return the same account. Sxerks3 65 — 8y

3 answers

Log in to vote
0
Answered by
Sxerks3 65
8 years ago

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.

Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
game.Players.PlayerAdded:connect(function(player)
    if player.Name == "0mrlight0" or player.Name == "edward538" then --You have to do the same thing for all players
        player.PlayerGui.Frame.ScreenGui.Button.Visible = true --PlayerGui is where you update the GUI's, StarterGui doesn't update through the player
    end
end)

0
I only want it for 0mrlight0 and edward538, not anyone else. 0mrlight0 40 — 8y
0
This method still wouldn't work, because the playergui wouldn't exist when the player is added. It only exists when the character is loaded, which typically occurs after the player is added onto the server. Sxerks3 65 — 8y
Log in to vote
-1
Answered by 8 years ago
Edited 8 years ago

You're going in the right direction, but you messed up. Just becuase you found the name of the first player player.Name == "0mrlight0", doesn't mean your going to find it in the next "edward538". You must tell the script what your looking for. In this case it'd be the name of "edward538". player.Name == "edward538"

game.Players.PlayerAdded:connect(function(player)
    if player.Name == "0mrlight0" or player.Name == "edward538" then
        player.PlayerGui.Frame.ScreenGui.Button.Visible = true
    end
end)

0
If you'd like to add more people I suggest making a table. OnlineSaga 10 — 8y
0
Whoops! You changed it in StarterGui. User#6546 35 — 8y
0
Didn't see that error in his script at first, fixed it. OnlineSaga 10 — 8y

Answer this question