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

Is there any way to shorten this?

I want to use math.random, but i'm not sure how or if it will work. Here is the script:

wait(2)
if script.Parent.Visible == true then 
script.Parent.Text = script.Parent.Fact1.Value
wait(6)
script.Parent.Text = script.Parent.Fact2.Value
wait(6)
script.Parent.Text = script.Parent.Tip1.Value
end

1 answer

✓ Accepted answer

Maybe, if you think like the most beginners, you will think on a script like this

local rand = math.random(1,3) -- draw a number between 1 and 3
wait(2)
if script.Parent.Visible == true then 
	if rand == 1 then
		script.Parent.Text = script.Parent.Fact1.Value
		wait(6)
	elseif rand == 2 then
		script.Parent.Text = script.Parent.Fact2.Value
		wait(6)
	elseif rand == 3 then
		script.Parent.Text = script.Parent.Tip1.Value
		wait(6)
	end
end

Obvoiusly, this is too long. Maybe you should use a table. You can consider it as a value container:

local myFirstTable = {nil, false, "dav1000999", 563754, math.huge, nil, "efl"}

So, you can use it to shorten your script. Once the three results use the same structure, we can replace them.

local values = {"Fact1", "Fact2", "Tip1"} -- gets the names
local num = math.random (1,3) -- draws a number
if script.Parent.Visible == true then
	script.Parent.Text = script.Parent:WaitForChild(values[num]).Value -- takes the name in basis of the number
	wait(6)
end

Hope it helps!

2 comments

0

It did thanks. :D

0

please be sure to accept answer

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