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

What is Wrong with my Math Equation Script?

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

  • 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

0

Still does not work.

0

I JUST TESTED IT AND IT WORKED FINE.

0

I only saw the First box My mistake.

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