Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Place updated Warning Gui?

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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() 
Ad

Answer this question