NEW PROBLEM - Gui wont change

Hey!

I am making a simple minigame test, for a friend, and I made this code:

Script
    -- Variables

game.Players.PlayerAdded:Connect(function(player)

 local status = game.StarterGui.Status.StatusLabel

local reward = 10

repeat
status.Text = "NEED MORE PLAYERS FOR MINIGAME"
until game.Players.NumPlayers >= 1

if game.Players.NumPlayers >= 1 then
	status.Text = "MINIGAME STARTING SOON"
	wait(5)
	status.Text = "OBJECTS LOADING"
	wait(5)
	local objects = game:GetService("ServerStorage").Objects:GetChildren()
	local clonedObject = objects[(math.random(1,#objects))]:Clone()
	clonedObject.Parent = workspace
    wait(5)
	status.Text = "OBJECTS HAVE BEEN LOADED"
end

end)

The status won’t change, even when the objects have been cloned.

Any help?

2 Likes

You are doing something completely wrong:
local clonedObject = (math.random(1,#objects)):Clone()

The correct method is:
local clonedObject = objects[(math.random(1,#objects))]:Clone()

2 Likes

Ahh i see now. Yes, i tried that method before, just forgot to put “objects” infront of math.random

also, just a note if you haven’t realize it yet
but you chose the wrong path for your gui
supposed to be on PlayerGui

I know it’s a little late and you’ve already got a solution, but the Random class seems to give a little more random results than the math.random() function.

It could just be a placebo and it isn’t actually any more random.

1 Like

They do the same thing as of now IIRC.

The algorithm used by Random is the XSH-RR variant of the PCG family.
In a nutshell, it’s is a fast algorithm with excellent statistical properties.
We’re planning to change math.random to use the same algorithm by early next year.

I believe this post was made in 2017. It has been 3 year since then, and that change has likely been implemented.

The only reason you might want to use the Random class is for an object oriented approach, or a case where you might need several “random” generators with different seeds.

Hey!
Thanks!

I have a new problem now - read the post.

I have tried a lot of things, but it won’t change.

Maybe I am blind but I cannot see it.

There is nothing in the output about this, it is just not changing. Ill try get more info.

EDIT: Trying to change it to OBJECTS HAVE BEEN LOADED.

You did:
local status = game.StarterGui.Status.StatusLabel

Which takes the GUI in the starterGui, not the playerGui. You need to do something like:
local status = game.Players.PlayerNameHere.PlayerGui.Status.StatusLabel