Specific tool for team

Hello, i’m currently working on a system where if a player buys a dev product then a specific team gets tools for 5 minutes then once the time is up the tools are no longer given. I am wondering on how to achieve this, if anyone could point me to some pages that may help that would be awesome :slight_smile:

When the player buys the dev product, find what team the player is on and find all players in that same team by use for i loops. Clone the tools and give it to the team and then after make it wait task.wait(300) and then destroy all clone tools within the player by using for i loops again

2 Likes

Something like this could work.

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")

local TeamNameToGiveToolsTo = "" -- The name of the team that you want to give the tools to
local Id = 0 -- Your productId here
local Time = 5 * 60 -- 5 minutes 

local Tools = -- The path to your folder with all of the tools in it

local function GiveTools()
	for i, Player in Players:GetPlayers() do
		if Player.Team.Name == TeamNameToGiveToolsTo then
			for i, Tool in Tools:GetChildren() do
				local NewTool = Tool:Clone()
				NewTool.Parent = Player.Backpack
				
				Debris:AddItem(NewTool, Time)
			end
		end
	end
end

local function HandlePurchase(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local productId = receiptInfo.ProductId
	if player and productId == Id then
		GiveTools()
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

MarketplaceService.ProcessReceipt = HandlePurchase
1 Like

Hey, for some reason this still gives another team the tool.

You could try using teamcolor then.

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local ServerStorage = game:GetService("ServerStorage")
local Debris = game:GetService("Debris")

local Teams = game:GetService("Teams")

local TeamNameToGiveToolsTo = Teams[""] -- The team that you want to give the tools to
local Id = 0 -- Your productId here
local Time = 5 * 60 -- 5 minutes 

local Tools = -- The path to your folder with all of the tools in it

local function GiveTools()
	for i, Player in Players:GetPlayers() do
		if Player.TeamColor == TeamNameToGiveToolsTo.TeamColor then
			for i, Tool in Tools:GetChildren() do
				local NewTool = Tool:Clone()
				NewTool.Parent = Player.Backpack

				Debris:AddItem(NewTool, Time)
			end
		end
	end
end

local function HandlePurchase(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local productId = receiptInfo.ProductId
	if player and productId == Id then
		GiveTools()
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

MarketplaceService.ProcessReceipt = HandlePurchase

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.