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

What is Wrong with my Math Equation Script?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

I have asked this before, but Got an answer that Only got rid of a error, Now this just doesnt work, Help.

Script:

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)

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago
  • 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.

0
Still does not work. IcyEvil 260 — 10y
0
I JUST TESTED IT AND IT WORKED FINE. BlueTaslem 18071 — 10y
0
I only saw the First box My mistake. IcyEvil 260 — 10y
Ad

Answer this question