Door not opening when message chatted

I’m making a puzzle game, where there’s a riddle posted on a chalkboard, and when a player says the answer in chat, the door opens. When I tested it when the model was in workspace, it worked. But when I tested it from being cloned to workspace from ReplicatedStorage, it doesn’t work.

riddle = math.random(1, 10)
answer = "e"
if riddle == 1 then
	script.Parent.SurfaceGui.TextLabel.Text = "I have 104 keys, but only 3 locks, only one enter and only one escape, and I have space but no room. What am I?"
	answer = "keyboard"
        --etc..
end

local player = game.Players.LocalPlayer
local door = script.Parent.Parent.Door

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.Chatted:connect(function(msg)
		if string.sub(string.lower(msg), 1,8)==string.lower(answer) then
			door:Destroy()
		end
	end)
end)

This script is placed inside the chalkboard, which is inside the entire level.

Not sure if this variable would be overlapping your PlayerAdded Event, try and remove that?

Is your script a LocalScript or server script?

A server script. The riddle will be for everyone playing.

local Players = game:GetService("Players")

local riddle = math.random(1, 10)
local answer = "e"

if riddle == 1 then
	script.Parent.SurfaceGui.TextLabel.Text = "I have 104 keys, but only 3 locks, only one enter and only one escape, and I have space but no room. What am I?"
	answer = "keyboard"
        --etc..
end

local door = script.Parent.Parent.Door

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		if string.sub(string.lower(msg), 1,#answer) == string.lower(answer) then
			door:Destroy()
		end
	end)
end)

still not working. I’m not getting any errors at all.

A little update, this entire thing is being cloned, if that helps. only the original’s door is working.

Try referencing the script inside ServerScriptService, and put this instead:

local Players = game:GetService("Players")

local riddle = math.random(1, 10)
local answer = "e"
local door = --Position of door--
local Chalkboard = --Position of Chalkboard--

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
        local NewMsg = string.sub(string.lower(msg), 1, #answer)
        print(NewMsg)
		if NewMsg == string.lower(answer) then
			door:Destroy()
		end
	end)
end)

if riddle == 1 then
	script.Parent.SurfaceGui.TextLabel.Text = "I have 104 keys, but only 3 locks, only one enter and only one escape, and I have space but no room. What am I?"
	answer = "keyboard"
        --etc..
end

What script inside ServerScriptService?

That script, place it inside ServerScriptService instead & try out the debugging one I sent

The game is going to shuffle the rooms, so I can’t be 100% accurate of where the door is.

Ok parent it in the board then, but could you at least try the script and see what outputs backs…?