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

How to categorize weapons and make is so you can only have one of each?

I'm wondering if you guy could guide into the correct path of categorizing my weapons in groups like "Primary" and "Secondary" so it could be easier to go about making a code that would allow the user to have only one of each category. I would also like to know how what I would have to add into my script

local ToolPickup = game.Lighting.ToolPickup

ToolPickup.OnServerEvent:Connect(function(Player)
	game.Lighting.Uzi:Clone().Parent = Player.Backpack
	game.Workspace.Part:Destroy()
end)

so it would make that if the player already has a one primary and secondary, he would have to trade the previous gun in that category to pick up the new one.

1 answer

✓ Accepted answer

I'm actually in the middle of working on the same thing

On your server side script do this

local ToolPickup = game.Lighting.ToolPickup

ToolPickup.OnServerEvent:Connect(function(Player, identtype)
	local uzi = game.Lighting.Uzi:Clone()
	uzi.Parent = Player.Backpack
	local plr = player.Character
	plr.Humaoind:UnequipTools()
	for x, v in next, player.Backpack:GetChildren() do
		if v:FindFirstChild(identtype) ~= nil then
			v:Remove()
		end
	end
	local ident = Instance.new("BoolValue", uzi)
	ident.Name = identtype
	game.Workspace.Part:Destroy()
end)

On your local side script do this and change "Primary" to the type of weapon you want it to identify as

--Other parts of your script
game.Lighting.ToolPickup:FireServer("Primary")
--Other parts of your script

1 comment

0

How would I add my other weapon which is an G36 and a primary into the script? Do I create a new local and implement it into the script or do I create a new script all together for that weapon? (I named it Part2)

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