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

How do I make a door with a randomly generated code?

Asked by 3 years ago

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 :)

1
do tostring(code) Vinceberget 1420 — 3y
0
It works, thank you so much! can you post this as an answer so I can mark it as one? PixelatedCube64 28 — 3y

1 answer

Log in to vote
1
Answered by
mroaan 95
3 years ago

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)
0
Thanks, sorry for missing that lol PixelatedCube64 28 — 3y
0
yeah no problem mroaan 95 — 3y
Ad

Answer this question