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

How Do I Avoid Having The Two Same Weapons?

Im Making a Airdrop Airdrop Works Well If You Dont Know The AirDrop Script, Here it is

-- Script Made By UglyPoe (RarityScript) And Minecrafter09031031 Changes The Script to Lucky Block Script
-- Instruction :
-- Make a Folder in ReplicatedStorage and Name it Tools, And then Add Weapon On It
	-- Also, Make Another Folder Name "Crates", -- This is where we put all the crate for RespawnSystem

local Weapon1 = game.ReplicatedStorage.Tools.Colorless -- Weapon 1
local Weapon2 = game.ReplicatedStorage.Tools.MagicalStaff -- Weapon 2
local Weapon3 = game.ReplicatedStorage.Tools.SaturnStaff -- Weapon 3
local Weapon4 = game.ReplicatedStorage.Tools.Determinator -- Weapon 4

local Items = {
	{Weapon1,1},
	{Weapon2,4},
	{Weapon3,5},
	{Weapon4,3} -- Higher Weight, Lower Rarity
}
local TotalWeight = 0

for _,ItemData in pairs(Items) do
	TotalWeight = TotalWeight + ItemData[2]
end

local function chooseRandomItem()
	local Chance = math.random(1,TotalWeight)
	local Counter = 0
	for _,ItemData in pairs(Items) do
		Counter = Counter + ItemData[2]
		if Chance <= Counter then
			return ItemData[1]
		end
	end
end

local click = script.Parent.ClickDetector

click.MouseClick:Connect(function(plr)
	local Tool = chooseRandomItem()
	local CloneTool = Tool:Clone()
	CloneTool.Parent = plr.Backpack
	
	local xyz = 1 * 60 -- Change 1 To A Number of Minute You Want
	
	script.Parent.Parent.Parent = game.ReplicatedStorage.Crates
	wait(xyz) 
	script.Parent.Parent.Parent = game.Workspace
end)

It works perfectly, But when i have SaturnStaff Tool, And I Click The Crate Again, Saturn Staff Appears Again, Can you Help Me Avoid Having 2 Same Tools?, Because if you Click a lot of Crates, 70 % Of player inventory is Saturn Staff , Haha

So Please Help

ADVANCED THANKS!

1 answer

✓ Accepted answer

Just detect if plr already have the weapon.

local Tool = nil
local CloneTool = nil
repeat
    local choose = chooseRandomItem()
    if plr.BackPack:FindFirstChild(choose.Name) or player.Character:FindFirstChild(choose.Name) then
    else
        Tool = choose
        CloneTool = choose:Clone()
        CloneTool.Parent = plr.Backpack
    end
until Tool ~= nil and CloneTool ~= nil

2 comments

0

Thanks For Help, It almost Work, But I Dont know Why The Main Weapon in Replicated Storage is the One Get Destroys Instead of The Tool That is Cloned

0

NVM, I FIXED IT, THANKS SO MUCH!!!!

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