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

How to save an inventoryGUI after a player dies?

Asked by 6 years ago
Edited 6 years ago

so I have a survival style inventory system, and I wonder how I could preserve all of the inventory slots in the inventory gui after the player dies in game.

--variables 
local currentweight = 0
local inv = {}
local plr = game.Players.LocalPlayer
--guis
local plrgui = plr:WaitForChild("PlayerGui")
local invGui = plrgui:WaitForChild("InventoryGUI")
local promptGui = plrgui:WaitForChild("PromptGUI")
local open = false
--mousr, char, remotes
local mouse = plr:GetMouse()
local remotes = game.ReplicatedStorage.Remotes
--services
local uis = game:GetService("UserInputService")
local ts = game:GetService("TweenService")
local rs = game:GetService("RunService")
--server shorthands
function tween (t,s,d,p,o)
    return ts:Create(o,TweenInfo.new(t,Enum.EasingStyle[s],Enum.EasingDirection[d]),p)
end
--functions
local function InputBegin (io,gpe)
    if gpe then return end
        if io.KeyCode == Enum.KeyCode.F then--pick up item
            if mouse.Target then
                local target = mouse.Target
                local name = target.Name
                local CanContain,weight = remotes.PickupItem:InvokeServer(target,plr.Character)
                if CanContain then
                    if il[name] == nil then
                        if inv[name] == nil then
                            inv[name] = {Amount = 1,Weight = weight}
                            local slotTemp = invGui.InvHolder.Slot
                            local MainInv = invGui.InvHolder.MainInv
                            local slot = slotTemp:Clone()
                            slot.Parent = MainInv
                            slot.Name = name
                            slot.Visible = true
                            slot.Amount.Text = inv[name].Amount
                            slot.ItemName.Text = name
                        else--change the amount
                            inv[name].Amount = inv[name].Amount + 1
                            invGui.InvHolder.MainInv[name].Amount.Text = tostring(inv[name].Amount)
                        end
                    end
                elseif not CanContain then
                    spawn(function()
                        invGui.IFT:TweenPosition(UDim2.new(.362,0,0,0),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,.4,true)
                        wait(2)
                        invGui.IFT:TweenPosition(UDim2.new(.362,0,-0.2,0),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,.4,true)
                    end)
                elseif CanContain == "Definitely No" then

                end
            end
    elseif io.KeyCode == Enum.KeyCode.C then--toggle inventory
        OpenClose(invGui.InvHolder)
    elseif io.KeyCode == Enum.KeyCode.E then--eat

    end
end
--events
uis.InputBegan:Connect(InputBegin)
0
you could just make it that the slots don't reset. greatneil80 2647 — 6y
0
you could just make it that the slots don't reset. greatneil80 2647 — 6y
0
how would i make it so that the slots dont reset, change the startergui also? And idk of any code in there that resets the gui upon death theking48989987 2147 — 6y
0
set the gui's ResetOnSpawn property to false the8bitdude11 358 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

set the gui's ResetOnSpawn property to false

Ad

Answer this question