So I was making a verification-kinda thing in my obby game that when you guessed the correct code (random each server) in the chat you will teleport to the next level, and when you guessed it wrong you will die, and start over. But the script is not working, I tried multiple ways to fix it and it's still not working. I tried putting print functions to the script and there are no prints in the dev console. Here is the code:
local notDEBOUNCE = game.ReplicatedStorage.THETRUEANSWER.Value while wait() do notDEBOUNCE = game.ReplicatedStorage.THETRUEANSWER.Value end game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) msg = string.lower(msg) if msg == (string.lower(tostring(notDEBOUNCE))) then if plr.SENDVERIFICATION.Value == true and plr.SENDVERIFICATION2.Value == true then plr.SENDVERIFICATION.Value = false plr.SENDVERIFICATION2.Value = true plr.leaderstats.Stage.Value = 51 plr.Character.Humanoid.Health = 0 print("success!!") end else if plr.SENDVERIFICATION.Value == true and plr.SENDVERIFICATION2.Value == true then plr.SENDVERIFICATION.Value = false plr.SENDVERIFICATION2.Value = true plr.leaderstats.Stage.Value = 50 plr.Character.Humanoid.Health = 0 print("wrong!!") end end end) end)
Hello, it is really easy! You put while loop before it connected the events which means they will never get connected because code will never reach it. Use spawn function or better put it after these connections. And that loop is not even needed, learn more about code mechanics.
local code = game.ReplicatedStorage.THETRUEANSWER local function onPlayerChatted(plr, msg) msg = string.lower(msg) if msg == (string.lower(tostring(code.Value))) then if plr.SENDVERIFICATION.Value and plr.SENDVERIFICATION2.Value then plr.SENDVERIFICATION.Value = false plr.SENDVERIFICATION2.Value = true plr.leaderstats.Stage.Value = 51 plr.Character.Humanoid.Health = 0 print("success!!") end else if plr.SENDVERIFICATION.Value and plr.SENDVERIFICATION2.Value then plr.SENDVERIFICATION.Value = false plr.SENDVERIFICATION2.Value = true plr.leaderstats.Stage.Value = 50 plr.Character.Humanoid.Health = 0 print("wrong!!") end end end game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) onPlayerChatted(plr, msg) end) end)