- Format your code correctly
game.Players.PlayerAdded:connect(function()
for i,v in pairs(game.Players:GetChildren()) do
v.Chatted:connect(function(msg)
if msg:lower():sub(1,5) == "math " then
m = Instance.new("Message")
elseif v.Chatted == "math 0 + 1 = " then
m.Parent = game.Workspace
m.Text = "1"
end
end)
end
end)
- Don't re loop over old players. If this worked, then a player who has been playing for a while would get one message PER player who has joined after him. That's not right. JUST connect to the new player joining:
game.Players.PlayerAdded:connect(function(newPlayer)
newPlayer.Chatted:connect(function(msg)
if msg:lower():sub(1,5) == "math " then
m = Instance.new("Message")
elseif newPlayer.Chatted == "math 0 + 1 = " then
m.Parent = game.Workspace
m.Text = "1"
end
end)
end)
- Use
msg not newPlayer.Chatted. The Chatted event is an event, not a string so your check for == "match 0 + 1 = " will always fail. Use msg like you did previously. Also, if we're using a lowercase version always, just do that in the beginning:
game.Players.PlayerAdded:connect(function(newPlayer)
newPlayer.Chatted:connect(
function(msg)
local msg, originalMsg = msg:lower(), msg;
if msg:sub(1,5) == "math " then
m = Instance.new("Message")
if msg == "math 0 + 1 = " then
m.Parent = game.Workspace
m.Text = "1"
end
end
end
)
end)
Note that this will be a capricious script since it requires a single space after the = sign.
3 comments
Still does not work.
I JUST TESTED IT AND IT WORKED FINE.
I only saw the First box My mistake.