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

Why do you need a string if there are brackets?

Asked by
Swolcu 2
4 years ago
Edited 4 years ago

im new to scripting and im trying to make a timer. on the last line of this script, there is an error saying Players.Swolcu.PlayerGui.ScreenGui.TextBox.Script:13: bad argument #3 to 'Text' (string expected, got nil)

debounce = true

function b()
        if debounce == true then
        debouce = false
        wait (1)
        timeS = (timeS + 1)
    end

    debounce = true
end

script.Parent.Text = (timeS)

how come there needs to be a string even thought i put brackets

thanks!

0
im pretty sure to turn a number into a string you have to use ToString(timeS) dont quote me on that though im not too good with strings Fad99 286 — 4y
0
now it's showing the textbox text as "TextBox" and when you click on it you can change it. help? Swolcu 2 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

There are two problems with your script.

  1. timeS is local to the b function, so outside of that function it will be nil.

  2. You never call the b function anywhere, so the code there never runs.

To create a simple timer like that you can just do something like this:

local timeS = 0
while true do
    timeS = timeS + 1
    script.Parent.Text = tostring(timeS)
    wait(1)
end

If you want other code to run after this, you can wrap it in a spawn

spawn(function()
    local timeS = 0
    while true do
        timeS = timeS + 1
        script.Parent.Text = tostring(timeS)
        wait(1)
    end
end)

-- Other code here
0
Thanks! It worked. Swolcu 2 — 4y
Ad

Answer this question