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

Why is my value == 0 even though it's changed?

Asked by
starmaq 1290 Moderation Voter
5 years ago
Edited 5 years ago

Ok, so I am working on a plugin and I had to make a script that assigns an id for each place. My plugin includes a coregui so I inserted a script and a Number Value object to it, and I'm parenting my screen gui to game:GetService("CoreGui") with the script and value inside. the script is generating a number for the id, after that i script:Destroy() it. i also print the id just to make sure it's working, and it does print it.

Code in this script:

local i = math.random(1, 1000000)
math.randomseed(i)
script.Parent.id.Value = tonumber(tostring(math.random()):sub(3, 12))
print(script.Parent.id.Value)
script:Destroy()

But after it's printed, and I try printing it again from somewhee else it prints 0. https://gyazo.com/c9dad33fae4b62c18c52c786dacc6951

What is wrong?

0
The value may be 0 because you did not specify what number should be sub-ed. Maybe try script.Parent.id.Value = tonumber(i):sub(3, 12)) 0_Halloween 166 — 5y
0
kk ill try starmaq 1290 — 5y
0
now it's always printing 0 even in the destroyed script starmaq 1290 — 5y
0
math.randomseed() isnt being used correctly, do math.randomseed(tick()) or use the Random class GoldAngelInDisguise 297 — 5y
0
You can use any seed you want. Using tick's return value as a seed is merely convention, not the law. User#24403 69 — 5y

Answer this question