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

Whats wrong with this?

Ive tried doing the following but it didnt work?

while wait() do
	TF = game.ReplicatedStorage["GUI_Drive"].TopFrame:clone()
	TF.Parent = game.StarterGui
	for i = 1, #Players do 
        TF.Parent = Players[i].PlayerGui
	end
end

How do i make the part where it gives the Players the GUI,Only run once in the script? The while wait() do loop is soppost to run as an entire round. Much appricated if you helped?

1 answer

I don't really understand what you mean in the last paragraph, but make sure you include the output. Players is a nil value because you don't define it anywhere, so there will be something in the output. Try this:

while wait() do
    local TF = game.ReplicatedStorage["GUI_Drive"].TopFrame:Clone() --Local variables are more efficient.
    TF.Parent = game.StarterGui
    local Players = game.Players:GetPlayers()
    for i = 1, #Players do 
        TF.Parent = Players[i].PlayerGui
    end
end

But this still will only give one player the GUI, since you only clone it once. You have to clone it for each and every player.

while wait() do
	local TF = game.ReplicatedStorage["GUI_Drive"].TopFrame:Clone()
	TF.Parent = game.StarterGui
	local Players = game.Players:GetPlayers()
	for i = 1, #Players do
		local gui = game.ReplicatedStorage["GUI_Drive"].TopFrame:Clone()
		gui.Parent = Players[i]:WaitForChild("PlayerGui") --Just in case it hasn't loaded yet.
	end
end

2 comments

0

Thanks,And what i meant is that it only runs ONCE in the loop,Per loop.

0

Read it now

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