So, I saw a post on here that talked about tables with chatted events a while ago and I attempted to make tables with chatted events unfortunately mine won't work... can someone please help? I put the following Block of code under StarterGui in a Local Script...
admins = {"KingLoneCat", "Player1"} messages = {"Reset", "Die"} game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) for i,v in next, messages do for _, admin in next, admins do if player.Name == admin and msg == v then player.Character:findFirstChild("Humanoid").Health = 0 end end end end) end)
Thank you for reading!
Problem
Your only problem here is using the PlayerAdded
event in a local script
. You can fix this in one of two ways
:
1. Server-side
You could make a server script
, put it in the ServerScriptStorage
, paste that code in it, and it will work fine.
2. Client-side
If you wanted to keep this in a local script
, you'd just removed the PlayerAdded
event and create the chatted signal on the local player
, like this:
local admins = {"KingLoneCat", "Player1"} local messages = {"Reset", "Die"} local player = game:GetService("Players").LocalPlayer -- Set the chat event with the local player player.Chatted:connect(function(msg) for i,v in next, messages do for _, admin in next, admins do if player.Name == admin and msg == v then player.Character:findFirstChild("Humanoid").Health = 0 end end end end)
Hope this helped, let me know if you have any questions.