I am trying to make an admin command script, and I have made a function that is supposed to get the owners name, which(I have not added this yet) will then insert the name into the Admins list.
I do not know why it is not working, and I am in need of help, here is the script.
local owner = game.CreatorId local admins = {"NameHere","AnotherAdmin"} -- Funcs game.Players.PlayerAdded:connect(function(plr) function GetOwnerName() if plr.UserId == owner then local x = plr.Name end end local ownername = GetOwnerName() local m = Instance.new("Message", workspace) m.Text = ( ownername.. " has Joined the server") end)
Any and all help is appreciated and needed.
This is not a good way to give admin commands ect as players can change their name, so I would use their id e.g plr.UserId
The main problem here is that you do not return the value from the function so nil will be present which you cannot concatenate a string with.
local owner = game.CreatorId local admins = {"NameHere","AnotherAdmin"} game.Players.PlayerAdded:connect(function(plr) -- so this local function needs the player now that ist local local function GetOwnerName(plr) if plr.UserId == owner then -- check if it is the owner return plr.Name -- the problem is that you dont return the info end return false -- not the owner so give false back end local m = Instance.new("Message", workspace) local plrName = GetOwnerName(plr) if plrName then m.Text = plrName .. " is the owner" else m.Text = plr.Name .. " is not the owner" end end)
My Recommendations
As I said at the top please use the player id as it will not change.
I think that you will want a level bases system as you have owner and admins so I would use a table e.g.
local adminList = { [use id here] = { permission level, gear ect}, -- other admins }
This will allow you to change or add who gets what.
If you want a function to return something, use return VALUE1,VALUE2,...
. In your example, use return plr.Name
instead of local x = plr.Name
.
Also, if there is no owner online, GetOwnerName() will (also) return nil, as it does now.
Under local ownername = GetOwnerName()
add this:
if not ownername then return end -- Code below here will only be used is the player is an owner