local Z=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local I=nil local S={}function S.start(S)local C=S.getCurrent local f=S.getNext local L=S.beforeUnload local n=Z:WaitForChild("\072\111\116\082\101\108\111\097\100\101\100")n.OnClientInvoke=function()n.OnClientInvoke=nil I=L()local Z=C()local S=Z.Parent local y=f()Z:Destroy()y.Parent=S end end function S.getSavedState()return I end return S
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local savedState = nil

local HotReloadClient = {}

function HotReloadClient.start(options)
    local getCurrent = options.getCurrent
    local getNext = options.getNext
    local beforeUnload = options.beforeUnload

    -- The server gets to decide when a hot-reload is triggered.
    local reloadBindable = ReplicatedStorage:WaitForChild("HotReloaded")

    reloadBindable.OnClientInvoke = function()
        reloadBindable.OnClientInvoke = nil

        savedState = beforeUnload()

        -- Do the job of StarterPlayerScripts over again to restart this script.
        -- This feels pretty hacky.
        local current = getCurrent()
        local parent = current.Parent
        local next = getNext()
        current:Destroy()
        next.Parent = parent
    end
end

function HotReloadClient.getSavedState() return savedState end

return HotReloadClient
