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

Problem With Chatted Event?

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

✓ Accepted answer

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.

1 comment

0

Thanks. I don't know how I overlooked that. +1 to you!

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