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

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

Asked by 6 years ago
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.

2
Just use tonumber() ? User#5423 17 — 6y
0
how would i use that @kingdom5? SyndicateHalo 40 — 6y
0
tonumber(link to the path) Developer_Kai 11 — 6y
0
hey look an infinite loop that can be replaced with an event.................................... hiimgoodpack 2009 — 6y
0
script.Parent.Value.Value = tonumber(script.Parent.Text), You can't set number value to a string. airassassin99 0 — 6y

2 answers

Log in to vote
2
Answered by 6 years ago
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
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 = SyndicateHalo 40 — 6y
0
Please use local variables. They are easier to access, and the local num at the top of the script is not necessary. hiimgoodpack 2009 — 6y
1
He is using local variables. Once a variable is defined as local, altering the value doesn't suddenly make it global. CootKitty 311 — 6y
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. CootKitty 311 — 6y
0
Did I just double negative? ... CootKitty 311 — 6y
Ad
Log in to vote
-1
Answered by
thesit123 509 Moderation Voter
6 years ago

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

Answer this question