Im trying to get a random tool to a player everytime they click a part but it doesnt seem to working and im not sure why. I cant figure out what the error means either.
local commonFolder = game:GetService("ReplicatedStorage").Catchables.Common
local uncommonFolder = game:GetService("ReplicatedStorage").Catchables.Uncommon
local rareFolder = game:GetService("ReplicatedStorage").Catchables.Rare
local legendaryFolder = game:GetService("ReplicatedStorage").Catchables.Legendary
local function onClicked(player)
local random = math.random(1,4)
print(random)
local backpack = player.Backpack
if random == 1 then
local randomCommon = commonFolder[math.random(1,#commonFolder)]:Clone()
randomCommon.Parent = backpack
else if random == 2 then
local randomUncommon = uncommonFolder[math.random(1,#uncommonFolder)]:Clone()
randomUncommon.Parent = backpack
elseif random == 3 then
local randomRare = rareFolder[math.random(1,#rareFolder)]:Clone()
randomRare.Parent = backpack
elseif random == 4 then
local randomLegendary = legendaryFolder[math.random(1,#legendaryFolder)]:Clone()
randomLegendary.Parent = backpack
end
end
end
ClickDetector.MouseClick:Connect(onClicked)```