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

Problem With Chatted Event?

Asked by
MrFlimsy 345 Moderation Voter
10 years ago

I'm trying to make it so that if someone in my list of admins types "/e msg (message)", it will create a new Message object in Workspace, display the message for 2.5 seconds, then destroy it. The problem is, when I try to use it, nothing happens and there is no output.

Here is the code:

local admins = {
    "MrFlimsy"
    "Interactivity"
    "NotAshley"
}

function isAdmin(player)
    for _,v in pairs(admins) do
        if v == player then
            return true
        end
    end
end

game.Players.PlayerAdded:connect(function(plr)
    plr.Chatted:connect(function(msg)
        local cmd = string.lower(msg)
        if string.sub(cmd,1,7) == "/e msg " then
            if string.len(cmd) > 7 then
                if isAdmin(plr) then
                    local m = Instance.new("Message",workspace)
                    m.Text = string.sub(msg,8,string.len(cmd))
                    wait(2.5)
                    m:destroy()
                end
            end
        end
    end)
end)

1 answer

Log in to vote
6
Answered by
Sublimus 992 Moderation Voter
10 years ago

You have to separate values in a table:

local admins = { --Note the commas
    "MrFlimsy",
    "Interactivity", 
    "NotAshley"
}

Also, you are trying to compare an object to a string, it should be:

                if isAdmin(plr.Name) then --Since plr is an object you have to get it's name since it's name is a string and that is what you are trying to compare to in the function.
0
Thanks. I don't know how I overlooked that. +1 to you! MrFlimsy 345 — 10y
Ad

Answer this question