Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why do you need a string if there are brackets?

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!

2 comments

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

0

now it's showing the textbox text as "TextBox" and when you click on it you can change it. help?

1 answer

✓ Accepted answer

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

1 comment

0

Thanks! It worked.

This discussion is preserved as it was. New answers, comments, and votes are closed.