ScreenGUI Changing Tips [SOLVED]

So I made a loading screen, but I want to add tips for the game in it. So basically like every few seconds the text on the screen changes to another tip and so fourth.

image

local tips = {
"tip1",
"tip2",
"tip3",
"tip4"
}

--The tips aren't actually named tip, I just don't want to put the actually tips here to remove clutter, but you get the point.

while true do
	wait(2)
	script.Parent.Text = tips
end

This is in a local script in the hint text.

The problem is that the tips aren’t changing and are just staying the same as the dummy text.

If anyone has a solution, please comment it and I’ll try it.

Thank you all.

try this

local tips = {
"tip1",
"tip2",
"tip3",
"tip4"
}

while task.wait(2) do
	local randomtip = math.random(1, #tips)
        script.Parent.Text = randomtip
end
1 Like

This should work:

local tips = {
"tip1",
"tip2",
"tip3",
"tip4"
}

while task.wait(2) do
	local randomtip = math.random(1, #tips)
    script.Parent.Text = tips[randomtip]
end
2 Likes

It starts changing, but it’s changing it to random numbers.
image

Try the one I’ve offered, it should work as you want.

Remember:
math.random ALWAYS returns a number.

1 Like

Thank you, it works. If I may ask, what does task.wait() do and how is it more beneficial than just using wait()?

Its a better improved version of wait

They both are used for delays.
I believe there are full-detailed posts on it on the forum.

Search for : Roblox - wait() or task.wait()

The issue in your code is you are setting the text to be the entire array of strings, rather than a string from the array.

The above solutions posted are meant to choose a random text, but I imagine desired behavior is it cycles through them to avoid repeated tips as much as possible.

Here’s an implementation you may find useful:

local SECONDS_BETWEEN_TIPS = 2

local tips = {
	"tip1",
	"tip2",
	"tip3",
	"tip4"
}

local textLabel = script.Parent

while true do
	for _, tip in ipairs(tips) do
		textLabel.Text = tip
		task.wait(SECONDS_BETWEEN_TIPS)
	end
end

Note that I swapped your wait for a task.wait; they are equivalent in terms how you use it, but task.wait is always preferred (and is a newer method). You can read more about it in the announcement post.

My interpretation of the difference:

The old wait method runs on a 30 Hz queue, whereas the new task.wait method runs on a 60 Hz queue. The 60 Hz queue gets processed before the 30 Hz queue, and if threads from either queue end up taking too much time in a cycle, it’s possible that not all threads in the 30 Hz queue will get resumed. This means there is no actual guarantee that your thread will ever resume if you use the old wait method, but there is that guarantee if you use the newer task.wait method.

Disclaimer: I haven’t read the details of how this works from a source of truth myself, this is just some information I’ve gleaned from other people over the years

1 Like