Okay so. Ive been trying to make a custom adminsystem for myself. I havent done something like that yet and also havent really worked with datastore. So i did it after a tutorial on Youtube.
Well, now to the problem. Somehow :FindFirstChild always gives back a nil, no matter what i type in the chat, even if its a player thats also ingame, can anyone help?
Code
local DataStoreService = game:GetService("DataStoreService")
local banDataStore = DataStoreService:GetDataStore("banDataStore")
local commands = {}
local prefix = ";"
local admins = {
"Flauschi_XD";
"Player1";
}
local function findplayer(name)
for i, player in pairs(game.Players:GetPlayers())do
if string.lower(player.Name) == name then
return player
end
end
return nil
end
local function isAdmin(player)
for _, v in pairs(admins) do
if v == player.Name then
return true
end
end
return false
end
commands.ban = function(player, arguments)
local playertoban = arguments[1]
local playertobebanned = game.Players:FindFirstChild(playertoban)
if playertobebanned == nil then
print("error")
else
local playerid = playertobebanned.UserId
local success, errormessage = pcall(function()
banDataStore.SetAsync(playerid, true)
end)
if success then
print(playertobebanned.." is now banned!")
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message, receipient)
if isAdmin(player)then
message = string.lower(message)
local splitstring = message:split(" ")
local commandtriger = splitstring[1]
local cmd = commandtriger:split(prefix)
local cmdname = cmd[2]
if commands[cmdname] then
local arguments = {}
for i = 2, #splitstring, 1 do
table.insert(arguments,splitstring[i])
end
commands[cmdname](player,arguments)
end
end
end)
end)