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

How do I make a player respawn with specific items?

Asked by 8 years ago

Hello, so today I was trying to make a player keep certain items like room keys when they reset. Currently, it works, unless they are holding the key in there hand. However, I need ALL room keys to be given back when they reset. Thanks!

local p = game.Players.LocalPlayer
local cards = {}
p.CharacterRemoving:connect(function(char)
    cards = {}
    for _,obj in pairs(p.Backpack:GetChildren()) do
        if obj then
            if string.sub(obj.Name, 1, 4) == "Room" then
                table.insert(cards, obj)
            end
        end
    end
end)
p.CharacterAdded:connect(function(char)
    for _,obj in pairs(cards) do
        obj.Parent = p.Backpack
    end
    cards = {}
end)
0
If they are holding it it would be in their Character rather their Backpack so you could check if it's in their Character. EssentialRoll 30 — 8y
0
This code is checking in the backpack, he wants everything in the backpack to be stored. FiredDusk 1466 — 8y
0
Fire, that is incorrect. And Essential, I tried adding that code in, and it kept giving me errors, so I removed it(I don't have that code anymore). FrostTaco 90 — 8y
1
Could you not just put it into StarterGear then remove it from there when they don't need the key anymore? User#13152 0 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

Hey!

So, you wanna make sure your players have their keeps and stuff with them even after they respawn? It's soo easy!! <3 :D

So, before we get into that, lets grab some biscuits.

API:Class/Backpack

A backpack is like an inventory, which is temporary, that is, the items in a backpack won't last if a player resets/respawns or gets killed.

Reference

API:Class/StarterPack

A starterpack is also an inventory. The difference between the backpack and the starterpack is that, if you add Items to a player's starterpack, they will not be added to the backpack immediately, they will be added when the player respawns, or begins new life, aka, Simply speaking, The items in the starter pack are copied/cloned into each player's Startergear and then into backpack.

Reference

API:Class/StarterGear

This is a personal inventory that copies items from StarterPack.

Reference

How'd you use them?

While you are coding, you can just drop the items that you want to player to retain with into the Player's StarterPack

In studio, it looks like this Click Here

When the game is running, each player gets a separate "StarterGear" instance. This is there for every player. This is how it looks when the game runs.

Click Here

0
Ohhhh! I didn't know how todo it with the players personal inventory. Thank you so much! FrostTaco 90 — 8y
Ad

Answer this question