How to make something happen if a player's chat message is the same as a value?

I tried making two server scripts (placed in Workspace, I’m not sure if that can be troublesome) where the player should get rewarded if they chat a number that matches the value they have as a child, but I can’t get it to work. It’s probably something related with the “if msg == plr.tnumber.Value then” line, but I’m not sure. Thanks in advance!

game.Players.PlayerAdded:connect(function(plr)

local tnumber = Instance.new("IntValue")

tnumber.Name = "tnumber"

tnumber.Value = math.random(100000,999999)

tnumber.Parent = plr

end)
local players = game:GetService("Players")

players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == plr.tnumber.Value then
			print("works!")
		end
	end)
end)

It looks like this is an IntValue, but messages typed in chat are strings. Even if everything you type is all numbers, it will always be a string. Try doing the following:

if msg == tostring(plr.tnumber.Value) then

1 Like