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