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

Extremely simple 6 line script isnt working?? (SIMPLE)

while true do
	if script.Parent.Text:match("%d+") then
script.Parent.Value.Value = script.Parent.Text
wait(1)
end
end

Its supposed to check if a text is an integer, and if that text is an integer its supposed to put that integer into a numbervalue.

When I check numbervalue it reads back as 0.

5 comments

2

Just use tonumber() ?

0

how would i use that @kingdom5?

0

tonumber(link to the path)

0

hey look an infinite loop that can be replaced with an event....................................

0

script.Parent.Value.Value = tonumber(script.Parent.Text), You can't set number value to a string.

2 answers

local num
while true do
	num = tonumber(script.Parent.Text) -- attempt to convert text to number
	if num then -- if non-nil, it was successful and 'num' equals the number
		script.Parent.Value.Value = num
	end
	wait(1)
end

5 comments

0

Yes, I used tonumber() and made a script similar to this yet it still will not work, looks like its time to give up =

0

Please use local variables. They are easier to access, and the local num at the top of the script is not necessary.

1

He is using local variables. Once a variable is defined as local, altering the value doesn't suddenly make it global.

0

The error probably has to do with the .Value.Value. Indexing something like this checks for properties before children, so they could be the case. If the value is an object value, I guess it would work. I'd be curious about that part though. Nothing wrong with the answer, I don't believe.

0

Did I just double negative? ...

Trying using string.gmatch.

while wait(1) do
	if string.gmatch(script.Parent.Text, "%d+") then
		script.Parent.Value.Value = script.Parent.Text
	end
end

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