Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Everytime we die/reset the Gamepass tools keeps spawning in my backpack, causing multiples?

As the titles says, I have a gamepass that continues to give you the tools everytime you reset and die, filling up the bag/inventory. How should I fix this?

Thanks for the help in advance.

local gamepass = script:WaitForChild("GamePassId")
local service = game:GetService("GamePassService")

game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(char)
    if service:PlayerHasPass(player,gamepass.Value) then
       local tools = game.ReplicatedStorage:WaitForChild("Gamepass")
       for i,v in pairs(tools:getChildren()) do
          if v:isA("Tool") then
             v:Clone().Parent = player:WaitForChild("Backpack")
             v:Clone().Parent = player:WaitForChild("StarterGear")
          end
     end
  
end
end)
end)

1 comment

0

Wouldn't you have a empty backpack when you respawn?

1 answer

✓ Accepted answer

Don't clone it to StarterGear each time they die. use CharacterAdded:Wait() to run the code only once.

local gamepass = script:WaitForChild("GamePassId")
local service = game:GetService("GamePassService")

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:Wait() --wait for the event only once
	if service:PlayerHasPass(player,gamepass.Value) then
		local tools = game.ReplicatedStorage:WaitForChild("Gamepass")
		for i,v in pairs(tools:getChildren()) do
			if v:isA("Tool") then
				v:Clone().Parent = player:WaitForChild("Backpack")
				v:Clone().Parent = player:WaitForChild("StarterGear")
			end
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.