Alright, so my admin commands script is kinda not working, here is the script.
Module Script:
local Commands = {}
Commands.tp = function()
print('This is a success of the teleport command.')
end
return Commands
ServerScriptService script:
local prefix = '?'
local commands = require(script.Commands)
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local splitString = message:split(' ') -- Splits the message as obvious
local fCommand = splitString[1]:split(prefix) -- Fired Command variable
if commands[fCommand] then
commands[fCommand[2]]()
end
end)
end)
The module script is a child of the ServerScriptService script.
If possible please explain on what I did wrong.
The script name of the ServerScriptService script is Admin Commands
local commands = require(script.Commands)
local prefix = '?'
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
local splitString = message:split(' ') -- Splits the message as obvious
local fCommand = splitString[1]:split(prefix) -- Fired Command variable
print('Chatted!')
if commands[fCommand] then
commands[fCommand[2]]()
end
end)
end)
local prefix = '?'
local commands = require(script.Commands)
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message:match("^%"..prefix) then
local args = message:split(" ")
local command = args[1]:gsub(prefix, ""):lower()
table.remove(args, 1)
if commands[command] then
-- Clean Args
for i, v in pairs(args) do
if i > 10 then args[i] = nil end
if tonumber(v) then args[i] = tonumber(v) end
end
-- Run Command
commands[command](args)
end
end
end)
end)