Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is this Chatted Command not working?

Asked by
loak 7
7 years ago

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

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) AdministratorReece 193 — 7y

2 answers

Log in to vote
1
Answered by
thesit123 509 Moderation Voter
7 years ago
Edited 7 years ago

Chatted function is the other way around:

RBXScriptSignal Chatted (string message, Player recipient)

0
This should've been a comment, not an answer. AdministratorReece 193 — 7y
0
Thanks for the answer for some reason I thought I had the right order. loak 7 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

Answer this question