So I've made a script that gives a player a gun and removes any other guns they have in the toolbar (So they can only have one at a time), But for some reason it's giving them the gun + 1 so each time they click it it's adding one and so on until their toolbar is full up.

Here is the script, i'm not too sure where i've gone wrong with it. Thanks in advance


Player=script.Parent.Parent.Parent.Parent.Parent.Parent
PlayerWorkspace=script.Parent.Parent.Parent.Parent.Parent.Parent.Name
wait(4)
function CheckSale()
		wait(1)
if Player.PurgeStats.Pistol2.Value == 1 then
	script.Parent.Text = "Equip"
	script.Parent.Parent.Buy.Visible = false
	
	script.Parent.MouseButton1Up:connect(function()
		if 	_G.Purge_Status == true then

		tools = Player.Backpack:GetChildren()
		for i = 1,#tools do 
			if #tools > 1 then
			tools[i]:Remove()
			end
		wait()
		end
		game.Lighting.Pistol2:Clone().Parent = game.Workspace[PlayerWorkspace]
		game.Workspace[PlayerWorkspace].Humanoid:UnequipTools()
			end
		end)
	end
end

script.Parent.MouseButton1Up:connect(function()
	CheckSale()
end)

Player.PurgeStats.Pistol2.Changed:connect(function (property)	
	CheckSale()	
end)
CheckSale()

2 comments

0

.Parent.Parent.Parent.Parent

0

Ill optimise that at a later time and that part works anyway, just need to fix it for now.