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

Is their a way to keep items in Backpack there?

Asked by 9 years ago
game.Workspace.Values.Guns.Changed:connect(function(g)
    if g == "Give" then
        local Player = game:GetService("Players").LocalPlayer
        local Item = game:GetService("ReplicatedStorage").Guns.Pistol:Clone()
        Item.Parent = Player.Backpack
    end
end)

I am trying to make something that gives a play a gun in their BackPack, but when they die they lose that item. Do I have to make something that detects if a player has died and if so restockthem with the item, or can I have something which even if the player dies, they keep the weapon?

I am not a noob to scripting, I have knowledge of it. I am not requesting any coding, just asking if it is possible, and maybe somethings I would need to add to the script.

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

When giving the item to the player, make a clone for both the Backpack and the StarterGear.

game.Workspace.Values.Guns.Changed:connect(function(g)
    if g == "Give" then
        local Item = game:GetService("ReplicatedStorage").Guns.Pistol
        Item:Clone().Parent = game.Players.LocalPlayer.Backpack
        Item:Clone().Parent = game.Players.LocalPlayer.StarterGear
    end
end)

-- WARNING - Changed Event isn't reliable at times

-Goulstem

0
StarterGear meaning startPack? NinjoOnline 1146 — 9y
0
No, it's a child of the player object. So like, 'Item:Clone().Parent = Player.StarterGear'. Goulstem 8144 — 9y
0
I have editted the question with the code I am using now. It is in a LocalScript. How could I clone and parent the same item twice? NinjoOnline 1146 — 9y
0
I edited my answer with it, hope I helped, np(: Goulstem 8144 — 9y
Ad

Answer this question