For my game King of the Hill, I am working on an admin system, but I have run into an issue.
Whilst making the :kick
command, I realised that the string cannot be identified with an Array Key.
Here is the script in full:
local Plrs = game:GetService("Players")
local Commands = {}
Commands.__Index = Commands
local LinkedCommands = {[':kick']=Commands.Kick}
function Commands.Kick(argument:string)
if string.split(argument,' ')[1] == argument then
local CurrentPlrs = Plrs:GetPlayers()
local PossiblePlayer
for i, v in pairs(CurrentPlrs) do
local PlrNameSection = string.sub(v.Name,1,#argument)
if PlrNameSection == argument then
PossiblePlayer = v
end
end
if PossiblePlayer then
PossiblePlayer:Kick()
end
end
end
Plrs.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(message)
local Start = string.split(message,' ')[1]
if LinkedCommands[Start] then
print("should've sent...")
local CmdN = LinkedCommands[Start]
local Arguement = string.sub(message,#Start+2,#message)
local Cmd = LinkedCommands[CmdN](Arguement)
end
end)
end)
The variable LinkedCommands
hosts what word at the start of the sentance is needed, and links it to a command function, like Commands.Kick
.
Currently I have no permission or arguement checking, but I know how to implent that and that is not a priority as of now.
When I type :kick c
, it should kick me since my 2017 username starts with ‘c’.
It kicks a player by checking which player’s starting characters are the same as the arguement, however, the issue is not with the :kick
command, it is with the linking process.
Even when the chat detects my first word as :kick
, it returns nil as it can’t find a key in LinkedCommands
called :kick
, but there is a value assigned to that key, so I have absalutely no idea what the issue is.