I have been going slightly crazy trying to make this work.
Goal:
I have made this script that is supposed to create a random code. Then, if a player types that code in chat, the door gets destroyed
Problem:
This code won't do anything. It doesn't give me an error message and there is no script errors according to Roblox studio. I have tried to use a bunch of other chat door scripts as well, but I came to the same problem.
Here's a cut version of my script (Cut out the parts that aren't giving me problems)
local code = math.random(100000,999999)
game.Players.PlayerAdded:Connect(function(p)
p.Chatted:Connect(function(message)
if message == code then
game.Workspace.Secret.SecretDoor:Destroy()
end
end)
end)
print(code)
Note: This script works if line 5 has quotations around it, but if I did "code" then it would be looking for the word code, not the local code.
Thank you for reading, hope I can find a solution to this infuriatingly small script I've been working on for 2 days :)

2 comments
do tostring(code)
It works, thank you so much! can you post this as an answer so I can mark it as one?