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

The weapon is duplicating when I resetted?

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


game.Players.PlayerAdded:connect(function(player) if service:PlayerHasPass(player,gamepass.Value)
 then local tools = game.ReplicatedStorage:WaitForChild("Tools")
 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)

2 answers

I think the PlayerAdded event will fire when you die somehow. To prevent this insert a BoolValue in the charachter.

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

game.Players.PlayerAdded:connect(function(player) if service:PlayerHasPass(player,gamepass.Value)
 then local tools = game.ReplicatedStorage:WaitForChild("Tools")
 for i,v in pairs(tools:GetChildren()) do 
	local boolvalue = Instance.new("BoolValue",player)
  if v:isA("Tool") and not boolvalue then
	v:Clone().Parent = player:WaitForChild("Backpack")
	v:Clone().Parent = player.WaitForChild("StarterGear")
	boolvalue.Value = true
  end
 end
end
end)

If this helps you let me know im not that good in scripting :)

2 comments

0

It doesn't work

0

Sorry then i can't help you.

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


game.Players.PlayerAdded:connect(function(player) 
	if service:PlayerHasPass(player,gamepass.Value) then
		
		local tools = game.ReplicatedStorage:WaitForChild("Tools")
		
		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") -- You have a period instead of a colon player.WaitForChild

			end
		end
	end
end)

Hope this helps <3

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