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

Place updated Warning Gui?

Everthing works perfect only when i will add an gui before game shutdown it wont works. Whats wrong?

script.Parent = nil 
local MPS = game:GetService("MarketplaceService") 
local Current_Version = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Updated
print("Updater:[CURRENT_SERVER_VERSION: "..Current_Version.."]")

function CheckLoop()
	while wait(1) do
		local N_Version = game:GetService("MarketplaceService"):GetProductInfo(game.PlaceId).Updated
		if N_Version ~= Current_Version then
			print("Updater:[Update found, Creating new server]")
			CreateNewServer()
		end
	end
end
for i,v in pairs(game.Players:GetPlayers()) do --Not working
a = script:findFirstChild("Lold"):Clone()--Not working
a.Parent = (v:FindFirstChild("PlayerGui") or v.Character)--Not working
end--Not working
function CreateNewServer()
	while wait() do 
		for i,v in pairs(game.Players:GetPlayers()) do 
			local d = script.NewServer:clone()
			d.Parent = (v:FindFirstChild("PlayerGui") or v:FindFirstChild("Backpack") or v.Character)
		end
	end
end
CheckLoop() 

1 answer

✓ Accepted answer

What I would do is to wrap the for loop in a function, use WaitForChild for finding the GUI and only using v:WaitForChild("PlayerGui") as the parent of the GUI. The script may not have found the GUI, or if it did, it may have gone to the player's character as PlayerGui wasn't found, so they won't see it.

Then, I'd call the GUI function we created before creating a new server. You may want to use wait() to delay the new server script so that you can see the GUI before the game is shut down.

You should get something like this:

script.Parent = nil 
local MPS = game:GetService("MarketplaceService") 
local Current_Version = MPS:GetProductInfo(game.PlaceId).Updated --You have a variable for the MarketplaceService. Use it for ease when writing code.
print("Updater:[CURRENT_SERVER_VERSION: "..Current_Version.."]")

function CheckLoop()
    while wait(1) do
        local N_Version = MPS:GetProductInfo(game.PlaceId).Updated
        if N_Version ~= Current_Version then
            print("Updater:[Update found, Creating new server]")
            ShowGUI()
            wait(1) --You can change the number inside the parenthesis if you want a shorter/longer delay.
            CreateNewServer()
        end
    end
end
function ShowGui()
	for i,v in pairs(game.Players:GetPlayers()) do
	local a = script:WaitForChild("Lold"):Clone() --Waits for the GUI, then clones it.
	a.Parent = v:WaitForChild("PlayerGui") --Waits for the Player's PlayerGui before setting the parent of the GUI clone.
end

function CreateNewServer()
    while wait() do 
        for i,v in pairs(game.Players:GetPlayers()) do 
            local d = script.NewServer:clone()
            d.Parent = (v:FindFirstChild("PlayerGui") or v:FindFirstChild("Backpack") or v.Character)
        end
    end
end

CheckLoop() 

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