Hello!

So I made this script where If a user purchases a gamepass, It will clone a upgraded version of a Item and delete the original Item and then adds a new weapon Into the folder "Melee". I want to modify the script so that only players with the gamepass will only get these

Gamepass script:

local GamePassID = 106120088

local MarketPlace = game:GetService("MarketplaceService")

game:GetService("Players").PlayerAdded:Connect(function(Plr)
	local PlayerHasGamePass = MarketPlace:UserOwnsGamePassAsync(Plr.UserId,GamePassID)
	if PlayerHasGamePass then
		local GOLDSTICKP2W = game:GetService("ReplicatedStorage").Upgrades.Melee["Golden Stick"]:Clone()
		GOLDSTICKP2W.Parent = game:GetService("ReplicatedStorage").Melee
		local GoldTouch = game:GetService("ReplicatedStorage").Upgrades.Melee["The Golden Arm"]:Clone()
		GoldTouch.Parent = game:GetService("ReplicatedStorage").Melee
		game:GetService("ReplicatedStorage").Melee["50Hand"]:Destroy()
	end
end)

Random Item Giver (Melee):

local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Folder = RS:WaitForChild("Melee")
-- Change the "Folder" if you change the folder name in Replicated Storage

local function onCharacterAdded(character)
	local Tools = Folder:GetChildren()
	local ToolsTable = Tools
	local chosenTools = {}

	repeat
		local selectedIndex = math.random(1, #ToolsTable)
		table.insert(chosenTools, ToolsTable[selectedIndex])
		table.remove(ToolsTable, selectedIndex)
	until #chosenTools >= 1
	-- Numbers of tools going to give

	local plr = Players:GetPlayerFromCharacter(character)
	for i,v in pairs(chosenTools) do
		Folder:FindFirstChild(v.Name):Clone().Parent = plr.Backpack
	end
end

local function onAdded(player)
	player.CharacterAdded:Connect(onCharacterAdded) -- Triggers when the player spawns or respawns
end

Players.PlayerAdded:Connect(onAdded)

1 comment

0

How about making a table and inserting the weapons inside then make it pick with "table[math.random(#table)]"?