Hi i have been trying for a few hour now but cant seem to fix it i have a script to keep inventory items on death and it works but it also duplicates starter pack items
here is the script
game.Players.PlayerAdded:Connect(function(plr)
local items = Instance.new("Folder")
plr.CharacterAdded:Connect(function(char)
local hum = char:FindFirstChild("Humanoid")
for i, v in pairs(items:GetChildren()) do
v.Parent = plr.Backpack
end
hum.HealthChanged:Connect(function()
if hum.Health <= 0 then
if char:FindFirstChildOfClass("Tool") then
char:FindFirstChildOfClass("Tool").Parent = items
end
for i, v in pairs(plr.Backpack:GetChildren()) do
v.Parent = items
end
end
end)
end)
Sounds like the perfect case to use StarterGear honestly. When a player purchases the weapon, it gets added to their StarterGear and one added to their Backpack for the first time.
StarterGear is a container that is automatically inserted into each Player when the player joins the
game. When a player spawns, the contents of that player's StarterGear is copied into the player's
Backpack. Additionally, when a player connects to a game that permits gear, all of the appropriate
gear Tool objects that the player owns are inserted into that player's StarterGear.
No, it isn’t. You’re thinking of the StarterPack service.
Unlike StarterPack, StarterGear is not a service but rather a child of each Player object --
this means that its contents are player-specific so that each player can have different Tools
within their StarterGear. It is not replicated to any client, including the owning player.
ok so basically in server script service i have 2 scripts one keep your inventory and the other one is SUPOSSED to limit it so only one of each tool is allowed
local items = Instance.new("Folder")
plr.CharacterAdded:Connect(function(char)
local hum = char:FindFirstChild("Humanoid")
for i, v in pairs(items:GetChildren()) do
v.Parent = plr.Backpack
end
hum.HealthChanged:Connect(function()
if hum.Health <= 0 then
if char:FindFirstChildOfClass("Tool") then
char:FindFirstChildOfClass("Tool").Parent = items
end
for i, v in pairs(plr.Backpack:GetChildren()) do
v.Parent = items
end
end
end)
end)
this one is suppoesed to only allow one of each tool
local hasAwardedItems = false
Player.CharacterAdded:Connect(function()
if hasAwardedItems then
return
end
– give them the item
hasAwardedItems = not hasAwardedItems
end)
Instead of doing all that, you could use StarterGear instead which will accomplish the same thing.
When you go to add a player’s weapon when they purchased, you just have to do
local weaponPurchased = path_to_weapon:Clone()
weaponPurchased.Parent = player.StarterGear
EDIT
Try this out in game and you’ll understand what I mean.
game.Players.PlayerAdded:Connect(function(player)
player:WaitForChild("StarterGear")
local gear = Instance.new("Tool", player.StarterGear)
for i = 1, 5 do
player:LoadCharacter()
wait(7)
end
end)
local hasAwardedItems = false
Player.CharacterAdded:Connect(function()
if hasAwardedItems then
return
end
– give them the item
hasAwardedItems = not hasAwardedItems
end)