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

Pets disappear from players inventory when player dies?

Asked by 4 years ago
Edited 4 years ago

Hello. Ive made a pet system, everything works well until the player dies. All of the pets the player had in their inventory disappear from their inventory with no errors. Does anybody know how I can fix this?

local function addToFrame(pet)


    local newTemplate = Template:Clone()
    newTemplate.Name = pet.Name
    newTemplate.PetName.Text = pet.Name
    newTemplate.Parent = scrollframe

    local NewPet = pet:Clone()
    NewPet.Parent = newTemplate.PetImage

    local camera = Instance.new("Camera")
    camera.CFrame = CFrame.new(NewPet.PrimaryPart.Position + (NewPet.PrimaryPart.CFrame.LookVector * 3),NewPet.PrimaryPart.Position)
    camera.Parent = newTemplate.PetImage

    newTemplate.PetImage.CurrentCamera = camera

    buttonconnections[#buttonconnections + 1] = newTemplate.MouseButton1Click:Connect(function()
        if newTemplate.Equipped.Text == "EQUIPPED" then
            -- they want to unequip it
            game.ReplicatedStorage.UnEquipPet:FireServer()
            newTemplate.Equipped.Text = "UNEQUIPPED"
            newTemplate.Equipped.TextColor3 = Color3.fromRGB(255,0,0)
        else
            game.ReplicatedStorage.EquipPet:FireServer(pet.Name)
            SetTemplateEquipped(newTemplate)
        end
        end)
end


game.ReplicatedStorage.SendData.OnClientEvent:Connect(function(PetNames)

    for i,petName in pairs(PetNames)do
        if game.ReplicatedStorage.Egg1:FindFirstChild(petName) then
            addToFrame(game.ReplicatedStorage.Egg1:FindFirstChild(petName))
        end

    end
end)

game.ReplicatedStorage.SetEquippedPet.OnClientEvent:Connect(function(PetName)
    if scrollframe:FindFirstChild(PetName)then
        SetTemplateEquipped(scrollframe[PetName])
    end
end)

2 answers

Log in to vote
0
Answered by 4 years ago

go the the screengui and set "ResetOnSpawn" to false

0
Thank you so much! I've been struggling with this problem for ages, and I just realised I could do that. mrdoghuman_yt 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Try to store the pets in a player folder created by a script (Example game.Players.LocalPlayer.PetStorage.PET) and if the player leaves the game, you will need to use datastores

Answer this question