I'm trying to use a ClickDetector in a part to give the player who clicks it a random weapon, but everytime I click it I get the same thing.
Code:
local gamepassID = 510675750
local weapons = game.ServerStorage.Weapons:GetChildren()
local random = weapons[math.random(1, #weapons)]
script.Parent.ClickDetector.MouseClick:connect(function (playerWhoClicked)
local player = playerWhoClicked
local mps = game:GetService("MarketplaceService")
local playerHasPass = mps:PlayerOwnsAsset(player, gamepassID)
if playerHasPass then
random:Clone().Parent = player.Backpack
else
mps:PromptPurchase(player, gamepassID)
end
end)
Don't know why I'd have to say this, but yes, there is more than one tool in the folder (duh)

3 comments
the random variable won't change if you don't set it again. Also, try to set the randomseed (math.randomseed()) to tick(). (math.randomseed(tick()))
Put the "random" variable INSIDE the MouseClick function. That way it will change every time.
Put the "random" variable INSIDE the MouseClick function. That way it will change every time.