I'm working on some admin commands as a little side project and I've come across a problem. My chatted event fires, but my module code doesn't...
local Commands = {}
function Commands.KillPlayer(playertoKill)
print("got here")
if game:FindFirstChild(playertoKill) ~= nil then
print("got here 2")
workspace[findPlayer(playertoKill)]:BreakJoints()
end
end
function findPlayer(playerName)
for _, player in ipairs(game.Players:GetPlayers()) do
if player.Name:lower() == playerName:lower() then
return player
end
end
end
return Commands
The main script in ServerScriptService
local Commands = require(game.ServerScriptService.Commands)
function onChatted(message, player)
if message:sub(1,5) == "!kill" then
Commands.KillPlayer(message:sub(7)) -- I've tested and it definitely gets to this point
end
end
game.Players.PlayerAdded:connect(function(player)
if player.Name == "MasterDaniel" then
player.Chatted:connect(function(message)
onChatted(message, player)
end)
end
end)
Does anyone know why it is broken? Nothing in the module prints, even though KillPlayer is definitely called from the main script.

6 comments
That's not a connection, and that won't work. Please don't give this misinformation again.
Try using a method ':' to index/call your function(s). So instead of 'Commands.KillPlayer()' do 'Commands:KillPlayer()', and index respectively.
actually using . is fine, its the way he uses workspace[findPlayer)
The thing is, the module never prints "got here", and from previous tests I know that the if statement in the other code is correctly evaluated.
Alright, Im going to completely redo this. There is so many different ways you can go with this.
Mine works fine, what are you talking about...