First would like to say that, I am 100% a noob at programming. I would appreciate any constructive criticism possible and or just simple tips. Just trying to mess with chat commands and I have looked at the guide on the Roblox wiki but, I wanted to try to write the code in a way that makes sense to me. Apparently what makes sense to me does not work so I was wondering If what I was programming is even close to being a working chunk of code.
Code -
local Players = game:GetService("Players") function adminCommands(player, msg) if msg == "kill" then player.Character.Humanoid:TakeDamage(100) end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(adminCommands) end)
Thanks, Loak
Chatted function is the other way around:
RBXScriptSignal Chatted (string message, Player recipient)
Problem:
When you named your variable "Players" and then did the PlayerAdded event it was over ridded with the variable. So in theory your code was reading game.game:GetService("Players") . Which is a big no no. Also it seems you were making parameters with no value.
Solution:
I took out the first game. and let the "Players" variable run so that there was no malfunction in the script. I also added a Chatted
event to run with a function so that you could call the function adminCommands
.
Code:
local Players = game:GetService("Players") function adminCommands(player, msg) if msg == "kill" then player.Character:BreakJoints() --As mentioned above I recommend using this as it is a much easier way and safer way. end end Players.PlayerAdded:Connect(function(plr) --Also get in the habit of doing :Connect and not :connect as :connect is deprecated plr.Chatted:Connect(function(msg) --I added this function event adminCommands(plr, msg) --You are calling it here now and filling the parameters in the function with value end) end)
Let me know if you have any problems or questions and I would be glad to help. If this helped you don't forget to accept my answer.