Need Some Help On Why My Code Isn't Working

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

it is not detect if the player has said there word or not - if word has not been said its not suppost to assign them a new word and do not have the word gui come up but those show up and happen anyways.
If the player has said there word it should assign them a new word after they have rejoined the game.

  1. I asked friends, looked on internet and asked chatgpt

I want it to detect if the player has said there word or not - if word has not been said do not assign them a new word and do not have the word gui come up.
If the player has said there word it should assign them a new word after they have rejoined the game.

Not looking for anyone to rewrite it i just want someone to help me fix the rest and make it work. I have also provided the game file for you to look at - please do not steal or claim as own.
Mintywork.rbxl (312.1 KB)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local wordList = {"apple", "about", "after", "again", "below", "bring", "could", "every", "first", "found", "great", "house", "learn", "never", "other", "place", "plant", "point", "right", "small", 
	"sound", "still", "study", "their", "there", "these", "thing", "think", "three", "under", "water", "where", "which", "world", "would", "write", "along", "begin", "black", "blue", 
	"body", "book", "call", "come", "done", "door", "down", "eat", "end", "face", "fact", "fall", "far", "fast", "find", "five", "food", "foot", "form", "four", "free", "from", 
	"game", "girl", "give", "good", "got", "hand", "have", "head", "hear", "help", "here", "high", "home", "hour", "idea", "keep", "kind", "know", "land", "last", "left", "life", 
	"like", "live", "long", "look", "made", "make", "many", "mark", "may", "meet", "mind", "more", "most", "move", "much", "name", "need", "next", "night", "none", "open", 
	"part", "past", "pick", "play", "pull", "put", "read", "ride", "room", "said", "same", "say", "see", "send", "set", "show", "side", "sit", "six", "size", "sleep", "slow", 
	"some", "song", "soon", "stop", "take", "tell", "test", "that", "them", "then", "they", "thin", "this", "time", "told", "too", "town", "tree", "true", "turn", "two", 
	"upon", "use", "very", "wait", "walk", "wall", "want", "was", "way", "week", "well", "went", "were", "what", "when", "wind", "wish", "with", "work", "yard", "year", "you", "your", 
	"zone", "able", "acid", "age", "air", "arm", "art", "bag", "bat", "bed", "bee", "bit", "box", "boy", "bus", "car", "cat", "cow", "day", "dog", "dry", "egg", "eye", "fan", "fat", 
	"fig", "fly", "fun", "gap", "gas", "get", "gum", "gun", "hat", "hen", "hit", "ice", "ill", "ink", "jet", "job", "joy", "key", "kid", "leg", "log", "man", "map", "mat", "mom", 
	"mud", "net", "new", "nut", "oak", "oil", "old", "one", "pan", "pet", "pig", "pop", "rat", "red", "run", "sad", "sea", "she", "sky", "son", "sun", "tap", "tax", "ten", "tip", 
	"top", "toy", "try", "van", "war", "win", "won", "yes", "yet", "zip", "zoo", "bake", "ball", "band", "bank", "bath", "bear", "beat", "been", "bell", "belt", "bend", "best", 
	"bill", "bird", "bite", "blue", "boil", "bold", "bolt", "bomb", "bond", "bone", "boom", "born", "boss", "both", "bowl", "bulk", "bull", "bump", "burn", "bush", "busy", "buzz", 
	"cake", "call", "calm", "came", "camp", "card", "care", "case", "cash", "cast", "cell", "chat", "chip", "city", "club", "coal", "coat", "code", "cold", "cook", "cool", "cope", 
	"copy", "cord", "core", "cost", "crew", "crop", "dark", "date", "dawn", "days", "dead", "deal", "dear", "deep", "desk", "dial", "dice", "diet", "disk", "dose", "drag", "draw", 
	"drop", "drug", "duck", "duet", "dull", "dump", "dust", "duty", "earn", "ease", "east", "easy", "echo", "edge", "edit", "eggs", "else", "ends", "envy", "epic", "evil", "exit", 
	"face", "fade", "fail", "fair", "fame", "farm", "fate", "fear", "feed", "feel", "feet", "fell", "felt", "file", "fill", "film", "fine", "fire", "firm", "fish", "flat", "flow", 
	"fold", "fool", "fore", "fork", "fort", "frog", "fuel", "full", "fund", "gain", "gala", "gang", "gate", "gave", "gear", "gift", "glad", "goal", "goes", "gold", "golf", "gray", 
	"grey", "grid", "gulf", "guts", "hail", "hair", "half", "hall", "hang", "hard", "harm", "hate", "hawk", "heal", "heat", "held", "hell", "herb", "hero", "hers", "hide", "hill", 
	"hint", "hire", "hold", "hole", "holy", "hone", "hood", "hook", "hope", "horn", "host", "huge", "hung", "hunt", "hurt", "idle", "inch", "iron", "item", "jack", "jail", "jars", 
	"java", "jaws", "jazz", "jean", "joke", "jump", "jury", "just", "kept", "kick", "kill", "king", "knew", "lack", "lady", "laid", "lake", "lane", "late", "lead", "leaf", "lean", 
	"less", "lift", "line", "link", "list", "load", "loan", "lock", "logo", "lord", "lose", "loss", "lost", "love", "luck", "mail", "main", "male", "mass", "mate", "meal", "mean", 
	"meat", "melt", "menu", "mere", "mild", "mode", "mood", "moon", "must", "navy", "near", "neck", "news", "nice", "nine", "nose", "note", "okay", "oral", "over", "pace", "pack", 
	"page", "paid", "pain", "pair", "park", "pass", "path", "peak", "pile", "pink", "plan", "plot", "plug", "plus", "poll", "pool", "poor", "port", "pose", "post", "pure", "push", 
	"race", "rain", "rank", "rare", "rate", "real", "rear", "rest", "rice", "rich", "ring", "rise", "risk", "road", "rock", "role", "roll", "roof", "root", "rose", "rule", "rush", 
	"safe", "sail", "salt", "sand", "save", "seat", "seed", "seek", "seem", "self", "sell", "sent", "ship", "shop", "shot", "shut", "sick", "sign", "site", "skin", "snow", "soft", 
	"soil", "sold", "sole", "sort", "soul", "spot", "star", "stay", "step", "such", "sure", "tale", "talk", "tall", "tank", "task", "team", "tend", "term", "text", "than", "thin", 
	"thus", "tiny", "toll", "tone", "tool", "tour", "trip", "tune", "type", "unit", "used", "user", "vast", "view", "vote", "wake", "ward", "warm", "wash", "wave", "ways", "weak", 
	"wear", "west", "whom", "wide", "wife", "wild", "will", "wine", "wing", "wire", "wise", "wood", "wore", "yeah", "zero", 
	"ace", "act", "add", "age", "aim", "air", "all", "and", "ant", "any", "ape", "apt", "arc", "are", "arm", "art", "ash", "ask", "ate", "awe", "axe", "bad", "bag", "ban", "bar", "bat", "bed", 
	"bee", "beg", "bet", "bid", "bin", "bit", "bog", "bop", "bow", "box", "boy", "bud", "bug", "bun", "bus", "but", "buy", "cab", "cad", "cam", "can", "cap", "car", "cat", "cod", "cog", "cot",
	"cow", "cox", "cry", "cub", "cud", "cue", "cup", "cut", "dab", "dad", "dam", "dan", "dash", "day", "den", "dew", "did", "die", "dig", "dim", "din", "dip", "doe", "dog", "don", "dot", 
	"dry", "dub", "dud", "due", "dug", "dye", "ear", "eat", "ebb", "eco", "egg", "ego", "elf", "elk", "elm", "emu", "end", "era", "eve", "eye", "fad", "fan", "far", "fat", "fax", "fed", 
	"fee", "fen", "few", "fib", "fig", "fin", "fir", "fit", "fix", "flu", "fly", "foe", "fog", "for", "fox", "fry", "fun", "fur", "gad", "gag", "gal", "gap", "gas", "gel", "gem", "get", 
	"gig", "gin", "got", "gut", "guy", "gym", "had", "ham", "has", "hat", "hay", "hem", "hen", "hes", "hid", "him", "hip", "his", "hit", "hog", "hop", "hot", "how", "hub", "hue", "hug", 
	"hum", "hut", "ice", "icy", "iff", "ill", "imp", "ink", "inn", "ion", "irk", "its", "ivy", "jab", "jag", "jam", "jar", "jaw", "jay", "jet", "jig", "job", "jog", "jot", "joy", "jug", 
	"jut", "ken", "key", "kid", "kin", "kit", "lab", "lac", "lad", "lag", "lam", "lap", "law", "lax", "lay", "lea", "led", "lee", "leg", "let", "lib", "lid", "lie", "lip", "lit", "lob", 
	"log", "lop", "lot", "low", "lug", "mad", "mag", "man", "map", "mat", "max", "may", "men", "met", "mid", "mix", "mob", "mod", "mom", "mop", "mud", "mug", "mum", "nab", "nag", "nap", 
	"nay", "net", "new", "nib", "nil", "nip", "nod", "nor", "not", "now", "nun", "nut", "oak", "oar", "odd", "off", "oft", "oil", "old", "one", "opt", "orb", "ore", "our", "out", "owe", 
	"owl", "own", "pad", "pal", "pan", "pap", "par", "pat", "paw", "pay", "pea", "peg", "pen", "pep", "per", "pet", "pew", "phi", "pie", "pig", "pin", "pip", "pit", "ply", "pod", "pop", 
	"pot", "pro", "pub", "pug", "pun", "pup", "put", " rag", "ram", "ran", "rap", "rat", "raw", "ray", "red", "rib", "rid", "rig", "rim", "rip", "rob", "rod", "roe", "rot", "row", "rub", 
	"rue", "rug", "rum", "run", "rye", "sad", "sap", "sat", "saw", "say", "sea", "see", "set", "sew", "she", "shy", "sic", "sin", "sip", "sir", "sis", "sit", "six", "ski", "sky", "sly", 
	"sob", "sod", "son", "sow", "soy", "spa", "spy", "sub", "sue", "sum", "sun", "sup", "tab", "tad", "tag", "tan", "tap", "tar", "tat", "tax", "tea", "ted", "tee", "ten", "the", "thy", 
	"tic", "tie", "tin", "tip", "toe", "ton", "top", "tor", "tot", "tow", "toy", "try", "tub", "tug", "two", "ugh", "ump", "uni", "van", "vet", "vow", "wag", "war", "was", "wax", "way", 
	"web", "wet", "who", "why", "wig", "win", "wit", "won", "woo", "wow", "wry", "yak", "yam", "yap", "yaw", "yay", "yen", "yes", "yet", "you", "zip", "zoo"}  -- Add your words here

local function isWordInList(word)
	for _, w in ipairs(wordList) do
		if w == word then
			return true
		end
	end
	return false
end

local wordLabel = script.Parent:WaitForChild("NewWord")
local okButton = script.Parent:WaitForChild("Ok")

okButton.Visible = false
okButton.Active = false

local chosenWord = nil

-- Word shuffle animation
local function animateWordShuffle(duration, interval)
	local elapsed = 0
	local lastWord = ""

	while elapsed < duration do
		lastWord = wordList[math.random(1, #wordList)]
		wordLabel.Text = lastWord
		task.wait(interval)
		elapsed += interval
	end

	chosenWord = lastWord
	wordLabel.Text = chosenWord

	okButton.Visible = true
	okButton.Active = true

	-- Send chosen word to server
	ReplicatedStorage:WaitForChild("WordChosenEvent"):FireServer(chosenWord)
end

animateWordShuffle(2, 0.05)
3 Likes

iterate through word list

in this loop, check if playerMessage:match(wordList[i]) exists
if true then return true, otherwise continue

i am not a coder myself i dont understand that. I am not trying to be rude or anything. cuz ik in the roblox server someone just told me do it yourself with no help so i came here.

local function HasSaid(message:string):string?
local needle = table.find(wordList,message)
if needle == nil return nil end
return message[needle]
end

Just do check:

if HasSaid(WordHere)~=nil then


end

Where would i place these codes cuz im confused

So do i.
I have no idea how the hell you structured your code.

i used chatgpt to make the code i dont understand any coding at all. and i also used the roblox ai aswell

Is it really so hard to just open website named https://luau.org or https://www.youtube.com/ or Documentation - Roblox Creator Hub ?
AI code looks awful,unreadable and worst of all… UNOPTIMIZED!

i tried learning but its still hard

Everyone struggles in the beginning, but that doesn’t mean that you need to vibe code.
Right now, ChatGPT will either lead you in a wrong direction/will confuse you/will kill your self respect by seeing “HOW COMPLICATED CODE IS” (even tho it isn’t), so focus on learning from human-made tutorials instead of relying on AI.

Or, learn by yourself and have ChatGPT clarify concepts you struggle with.

Avoiding a good tool because just it’s AI is a bit odd in my opinion. As long as you are learning by yourself alongside it, and you aren’t relying on it, definitely use it. But make sure you don’t find yourself generating entire scripts with it.

2 Likes

im currently diagnosing the issue in my own studio server, just give me a moment and ill get back to you with results

ok so if im right, what your asking for is when they leave the game without saying their word. when they rejoin it should NOT assign them with a new word. Am I correct?

yes thats is what i am saying. i dont want people to cheat

I know this is not going to solve your problem, but as @Yarik_superpro said, using ChatGPT to create systems, mainly robust systems, is not a good idea. ChatGPT will lead you to confusion most likely, and you won’t know how to fix a problem when you face one, since you do not have the necessary knowledge for it. I recommend that you learn at least the basics of scripting, so you can have an idea about what you are doing, and consequently fix everything you need to.

:point_up_2:

1 Like

However, since I know how hard it is, I can try explaining stuff so you don’t get way too confused about anything

This may not be what you want. When you check for w == word, you are seeing if it is exactly equal to the word you specified, which may not be what you want, since the player can type Apple, but the array has only apple → will return false consequently.

A way to fix it is to lower the string, using string.lower(word), which will make all of the characters from the message in lowercase: string | Documentation - Roblox Creator Hub.

@Yarik_superpro already sent you a valid way to check for the existence of the word, you would just increment with what I said you to do:

local function isAValidWord(message : string) : string? -- Changing function name for clarity
    if not typeof(message) == "string" then return end -- Making sure message is a string. This can be translated as: "If the type of the message is not a string/text/character/word, then return 'nil'/'nothing'. When we don't specify what is next to return, it's automatically 'nil' (you can reach this conclusion by just checking that there is 'nothing' after return)

    local needle = table.find(wordList, string.lower(message)) -- table.find is a function that retrives the "index" (a.k.a. position) of the specified value you send to the second parameter inside the 'table', specified by the first parameter. It returns 'nil' if no item is found.

    return needle and message -- This will return the message, or 'nil', which is basically 'nothing', if it doesn't exist. This line can be easily interpreted as: "If the needle exists (i.e. 'table.find' found the 'position' of the element), then return the message provided by the function."
end

This line of code will ‘call’ the function (in my case, the name of the function is ‘isAValidWord’) immediately, and will check if the value returned by the function is not ‘nothing’, in other words, if it exists.

I suppose there is a separate script that handles the message thing. In this case, you will just implement everything we have explained there. I hope this helped you clarify stuff ^^. I will send you some posts regarding scripting tutorials, so you can at least have the basic idea of what it is!

1 Like

ok let me know anything if you ever find a solution. thanks

Use AI as a tool, not the solution. Learn the basics of Luau and the engine.

If you’re trying to listen to chat messages being sent from the local player, see TextChatService.SendingMessage.