Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is this Chatted Command not working?

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

1 comment

0

Don't use TakeDamage for killing people. It's easier for exploiters to bypass and whatnot. Even kill() can't work. Just use BreakJoints() and it'll wipe em out. Also, your player you want to kill is located in workspace. Try game.Workspace:FindFirstChild(player)

2 answers

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.