I saw a couple of games on roblox about the whole oh you cant say this word or you have this number of words and thought it'll be a fun challenge to set myself to make a small game which gives you a set amount of words and if you use up all of them you get banned from the game.
Now everything works as intended, the value, the subtraction when you say something, the correct amount of words, the kick when you run out of words
But I have run into an issue, I have a overhead gui over the player that displays the number of words you can utilize until you are banned from the game. I have a line of code in the player.Chatted event where it updates the text but it doesn't actually happen and it just stays the same as the number you first start out with.
Here is the code if anyone would like to help, thank you in advance.
local wordsGui = game:GetService("ServerStorage"):WaitForChild("Overhead"):WaitForChild("wordsLeft") game.Players.PlayerAdded:Connect(function(player) local hasWords = true local rollWords = math.random(1, 100) local wordsLeft = Instance.new("IntValue", player) wordsLeft.Name = "wordsLeft" wordsLeft.Value = rollWords wordsGui.Text = ("Words left: "..wordsLeft.Value) player.Chatted:Connect(function(msg) local message = msg local amount = #string.split(message, " ") print(amount) wordsLeft.Value -= amount wordsGui.Text = ("Words left: "..wordsLeft.Value) if wordsLeft.Value <= 0 then local kickQuotes = {" L bozo", " L + ratio", " because you are stupid", ", you could've chosen literally anything better to say", " get good kid"} local randomKickQuote = math.random(1, 5) player:Kick("Out of words"..kickQuotes[randomKickQuote]) end end) end)
The problem is that local variables are always the same and they do not update. Use global variable instead but it will display error if it's used inside functions. Try using it outside of the function so it will update and will not stay the same.
hey you! have you ever heard of enes? if you are in trouble, better call enes!
nothing worked but after a bit I figured it out and forgot to send it here
essentially I was updating the value of the gui in serverstorage and not the one on the player