admins = {
["tjtorin"] = true
}
prefix = ":"
function newCmd(plr,msg,name,code)
if admins[plr.Name] then
if msg == prefix..name then
spawn(code())
end
end
end
-- FUNCTIONS
------------------------
function kill(plr)
game.Players[plr.Name].Character.Head:Destroy()
end
------------------------
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
newCmd(plr,msg,"kill",kill(plr)) -- This is only supposed to run the kill(plr) if the player chatted is an admin but it runs if anyone says anything because its a function and its being called as an argument but how do I get it not to run here?
end)
end)
COMMUNITY QUESTION
How do I make my function now run when it is an argument?
1 answer
Simple. All you have to do is switch the parameters. There is no way to avoid running the kill function if you're going to include the function as an argument. Instead, do this:
admins = {
["tjtorin"] = true
}
prefix = ":"
function newCmd(player,msg,name,code)
if admins[player.Name] then
if msg == prefix..name then
spawn(code(player)) -- place arguments inside here, AFTER the checks are made.
end
end
end
-- FUNCTIONS
------------------------
function kill(plr)
if plr ~= nil then
game.Players[plr.Name].Character.Head:Destroy()
end
end
------------------------
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
newCmd(plr, msg, "kill", kill) -- just don't include the parameters...
end)
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
you need some return
@laughablehaha But if I do that then I can't do functions that require different params