Gives certain amount of tools according to the amount of players in the game

Hey Roblox devs. I’ve been testing my game with multiple players now, and I came across a weird problem. So, I have a menu that can give players weapons, and if they select a weapon it will be added to their inventory. The thing is, when there’s say 2 players in the game and one player selects a weapon, it clones twice into that player’s inventory, so now that player has 2 guns. Say there were 3 players in the game and one player selected a gun, that gun would get cloned 3 times so now that player has 3 guns in their inventory.

I thought this was very weird, since I don’t have any code using the amount of players in the game. I am using remote events for when the player selects the gun and discards it from their inventory, meaning I have a local script (checks to see if the player clicks the select button) and a server script (clones the gun into the player’s inventory, and also removes it from the player’s inventory).

Please let me know what the problem may be. If you need to see any of my scripts, I’ll be glad to show it.

3 Likes

Can you send me the script, please?

2 Likes

Not much at all we can do without the code.

Here is the local script:

	selectButton.MouseButton1Down:Connect(function()
		selectButton.MouseButton1Up:Connect(function()
			selectButton.Visible = false
			selectButton.Active = false
			DiscardButton.Visible = true
			DiscardButton.Active = true
		end)
		GunEquip:FireServer(ARselected)
		
		globalGunSelected = "Blackout"
	end)
	
	DiscardButton.MouseButton1Down:Connect(function()
		DiscardButton.MouseButton1Up:Connect(function()
			selectButton.Visible = true
			selectButton.Active = true
			DiscardButton.Visible = false
			DiscardButton.Active =false
		end)
		GunUnequip:FireServer(ARselected)
		
		globalGunSelected = nil
	end)

Here is the server script:

local GunEquip = game.ReplicatedStorage.gunEvents.GunEquip
local Blackout = game.ReplicatedStorage.guns.Blackout

GunEquip.OnServerEvent:Connect(function(player, ARselected)	
	if ARselected == ".300 AAC Blackout" then
		local BlackoutClone = Blackout:Clone()
		BlackoutClone.Parent = player.Backpack
	end
end)
local GunUnequip = game.ReplicatedStorage.gunEvents.GunUnequip
local BlackoutClone

GunUnequip.OnServerEvent:Connect(function(player, ARselected)
	if ARselected == ".300 AAC Blackout" then
		if player.Backpack:FindFirstChild("Blackout") then
			BlackoutClone = player.Backpack.Blackout
			
			BlackoutClone.Parent = game.ServerStorage.TrashCan
		elseif player.Character:FindFirstChild("Blackout") then
			BlackoutClone = player.Character.Blackout
			
			BlackoutClone:Destroy()
		end	
	end
end)

Blackout is the gun name.