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

Why won't the text update value?

Asked by 1 year ago

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)
0
That text might get you banned, knowing roblox moderation. Sabailuridze 126 — 1y
0
ong lol ABDJackioZoAlt1 37 — 1y

3 answers

Log in to vote
0
Answered by 1 year ago

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.

Ad
Log in to vote
0
Answered by
enes223 327 Moderation Voter
1 year ago

hey you! have you ever heard of enes? if you are in trouble, better call enes!

Log in to vote
0
Answered by 1 year ago

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

Answer this question