I’m currently creating a system where the first player that joins the server will be set as the “Server Owner”. This is in an attempt to create an admin system where there is a server owner who has HeadAdmin inside of HD admin. How should I go about creating a script to give HD Admin HeadAdmin to only the first person that joins the server? Thanks! (Let me know if you have any questions as this rather vague)
Here’s what I would do for this:
I would first create a table variable where I could store the server owner’s name or UserID.
Then detect whenever a player joins using the .PlayerAdded()
event and store the player in the table and disconnect the function from the event inside the function, this way only one player will be added into the table.
Here’s an example:
local Players = game:GetService("Players")
local ServerOwners = {}
event = Players.PlayerAdded:Connect(function(Player)
table.insert(ServerOwners, player.UserId)
event:Disconnect() -- Prevent the event function from running again
end)
I would just say just check if the Player Count is less than 1
when a Player leaves, if there is one Player, assign that Player as the Owner.
With Private Servers, only the Server Owner is the Owner
And once the server owner leaves the game, you can remove their UserID from the table with .PlayerRemoving
.
That’s another option, yeah.
There’s honestly a lot of options how to code this.
How would it be possible to get the player from player.UserId?
Players.GetPlayerByUserId()
is the function you are looking for
I’m just hoping to give ServerOwner to the first person that joins the server. (in the HD admin settings)
Ranks = {
{5, "Owner", };
{4, "ServerOwner", {"",0}, };
{3, "Admin", {"",0}, }; --here
{2, "Mod", {"",0}, };
{1, "VIP", {"",0}, };
{0, "NonAdmin", };
};
I guess you could use this but I may be wrong:
Ranks = {
{5, "Owner", };
{4, "ServerOwner", Users = {"", Index = 0}, };
{3, "Admin", {"",0}, }; --here
{2, "Mod", {"",0}, };
{1, "VIP", {"",0}, };
{0, "NonAdmin", };
};
event = Players.PlayerAdded:Connect(function(Player)
table.insert(Ranks[2].Users, player.Name)
Ranks[2].Users.Index += 1
event:Disconnect() -- Prevent the event function from running again
end)
I might have made it too confusing because my brain cell lacking brain cannot think of any more readable solution. Also I suggest you to not use HD Admin, it doesn’t really bring attention to your game because everyone thinks you use free models for your game and it also crashes studio (Possibly in-game as well). I scripted my own admin commands and I’d say it’s very easy to do so.
The difficult part about a custom admin system is the anticheat. I could most likely make one, but it just makes more sense for me to use HD admin.
I apologize, but I’m confused. Ranks[2]
? And there is still the issue with player.Name
.
Thanks for your responses. They’re extremely helpful and well thought out.
Oh right, the player
isn’t capitalized. You can capitalize the first letter.
And you have a curvy bracket here, remove it:
The very last curvy bracket btw
I’m also not sure what you mean by anticheat. I don’t think there are anticheats for admin systems so if you could elaborate, I would be able to help you out with that as well!
The prevention of exploiters giving themselves admin, for example.
I may be completely wrong, but I believe that bracket is necessary to the code, correct?
Yes, it is. That bracket would indicate that there’s another variable or table coming after the ranks table but actually there isn’t.
And this isn’t possible. Admin commands are on server scripts and exploiters can’t see server scripts or modify them. Worse thing they can do is delete local scripts which they can see and fire remote events that aren’t protected.
How should I fix it then? Apologies, I’m rather uneducated on scripting. I’m a builder not a scripter but I’ve decided to take upon myself an indie game. I’m still attempting to learn, but my scripting knowledge is still faily limited.
I suggest watching TheDevKing videos. I learned everything from him, he’s great at explaining.
Just remove that curly bracket and capitalize the player
in player.Name
Indeed, you need to protect your remoteEvents which is difficult. Any remote event from client to the server is dangerous as any exploiter can fire a remote event. Imagine an exploiter firing a remote event to ban players or make themselves fly. Additionally, making an admin system work with an anti cheat is very difficult as it’s hard to tell when someone is using admin or exploiting.
Apologies for that messy paragraph.