Limit of one of every item script

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)

end)

5 Likes

Is there a reason why you do not use the StarterGear?

1 Like

Did you set the Parent of the folder to a certain place?

because im making a combat game where you buy weapons and i want them to save to your player

1 Like

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.

StarterGear | Documentation - Roblox Creator Hub

1 Like

its parent is serverscriptservice

if i put a certain weapon into starter gear from what i know its global and aplys to all players

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.

where is starter gear located?

I am a little confused because when you create the folder where is the line of code where you parent it?

1 Like

It is located inside the Player object. You can access it via doing this-

game.Players.PlayerAdded:Connect(function(plr)
    local starterGear = plr:WaitForChild("StarterGear")
    -- from here add the gear
end)

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

1 Like

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)

end)
This one keeps inventory

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)

1 Like

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)

Pay attention to the player’s backpack.

1 Like



Screenshot 2023-08-12 220523

1 Like

You could probably check if the player died then create a if statement to check if they already had the weapon

1 Like

If they used the StarterGear they wouldn’t have to do this in the first place. :xd:

thats what this script is supposed to do

i cant do that i have multiple scripts that will overlap if i do that

1 Like

this script is supposed to check

local hasAwardedItems = false
Player.CharacterAdded:Connect(function()
if hasAwardedItems then
return
end
– give them the item
hasAwardedItems = not hasAwardedItems
end)