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

player.Chatted() function not working?

Asked by 3 years ago

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:

01local notDEBOUNCE = game.ReplicatedStorage.THETRUEANSWER.Value
02 
03while wait() do
04    notDEBOUNCE = game.ReplicatedStorage.THETRUEANSWER.Value
05end
06 
07game.Players.PlayerAdded:Connect(function(plr)
08    plr.Chatted:Connect(function(msg)
09        msg = string.lower(msg)
10        if msg == (string.lower(tostring(notDEBOUNCE))) then
11            if plr.SENDVERIFICATION.Value == true and plr.SENDVERIFICATION2.Value == true then
12                plr.SENDVERIFICATION.Value = false
13                plr.SENDVERIFICATION2.Value = true
14                plr.leaderstats.Stage.Value = 51
15                plr.Character.Humanoid.Health = 0
View all 28 lines...
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. Ziffixture 6913 — 3y
0
I do not see the need for that loop, either. Not to mention the name "notDEBOUNCE"...? Compare THETRUEANSWER directly. Ziffixture 6913 — 3y
0
Also I would suggest using camel case for your variable naming. It cleans things up a lot. KingDomas 153 — 3y
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 T3_MasterGamer 2189 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago

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.

01local code = game.ReplicatedStorage.THETRUEANSWER
02 
03local function onPlayerChatted(plr, msg)
04   msg = string.lower(msg)
05   if msg == (string.lower(tostring(code.Value))) then
06       if plr.SENDVERIFICATION.Value and plr.SENDVERIFICATION2.Value then
07           plr.SENDVERIFICATION.Value = false
08           plr.SENDVERIFICATION2.Value = true
09           plr.leaderstats.Stage.Value = 51
10           plr.Character.Humanoid.Health = 0
11           print("success!!")
12       end
13   else
14       if plr.SENDVERIFICATION.Value and plr.SENDVERIFICATION2.Value then
15           plr.SENDVERIFICATION.Value = false
View all 28 lines...
0
oh ok i'l try it later when roblox is not down T3_MasterGamer 2189 — 3y
Ad

Answer this question