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

Having trouble with using tables with chatted events please help?

Asked by 8 years ago

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!

1 answer

Log in to vote
2
Answered by 8 years ago

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.

0
How would I make an admin chatted event using 3 things like "Speed KingLoneCat 100" KingLoneCat 2642 — 8y
Ad

Answer this question