Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

player.Chatted() function not working?

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)

4 comments

1

My man, how could you have forgotten the basic principle of a loop? Loops REPEAT code; your program is indefinitely stuck on the 4th line.

0

I do not see the need for that loop, either. Not to mention the name "notDEBOUNCE"...? Compare THETRUEANSWER directly.

0

Also I would suggest using camel case for your variable naming. It cleans things up a lot.

0

thx for the comments i didnt know loop could get stuck and repeat the whole code, im still at beginner level in coding. also i added the loop because i want the variable to update every second because it prints a blank when try to print the variable

1 answer

✓ Accepted answer

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)

1 comment

0

oh ok i'l try it later when roblox is not down

This discussion is preserved as it was. New answers, comments, and votes are closed.