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 :)
player.Chatted event parameters are only two and they are strings and instances there is no numberValue so you need to convert it into a string.. you might say how? well using tostring() whatever you put inside those brackets will turn into a string even if it was a string it will turn into a string.. Lol
local code = math.random(100000,999999) game.Players.PlayerAdded:Connect(function(p) p.Chatted:Connect(function(message) if message == tostring(code) then game.Workspace.Secret.SecretDoor:Destroy() end end) end) print(code)