I am currently working on a ProximityPrompt gear giver, and I have trouble preventing having multiple of the same gear in one’s inventory.
2 Likes
-- reference to tool that you want to give to the player
local toolToGive = tool
-- try to find a tool with the same name as the tool that you want to give
local playerBackpackTool = player.Backpack:FindFirstChild(toolToGive.Name) or player.Character:FindFirstChild(toolToGive.Name)
-- if tool with same name doesn't exist then
if not playerBackpackTool then
-- give tool to player
toolToGive:Clone().Parent = player.Backpack
end
3 Likes
You could also use if you wanted to give multiple tools:
To everyone:
local Tools = {
game.ServerStorage.TestTool
}
function RunThroughTools(player)
local BP = player.Backpack
for i,tool in pairs(Tools) do
if tool:IsA("Tool") and not BP[tool.Name] then
tool:Clone().Parent = BP
end
end
end
game.Players.PlayerAdded:Connect(function(player)
RunThroughTools(player)
player.CharacterAdded:Connect(function()
RunThroughTools(player)
end)
end)
Or if you wanted to only give certain people tools you could do something like this:
local PlayerList = {
[3000392] = {
ExampleTool = {
Tool = game.ServerStorage.TestTool,
Give = true
}
}
}
function GiveTools(Tbl,plr)
local BP = plr.Backpack
for i,tool in pairs(Tbl) do
if tool:IsA("Tool") and not BP[tool.Name] then
tool:Clone().Parent = BP
end
end
end
function Check(player)
local Tools = {}
local Data = PlayerList[player.Name] or PlayerList[player.UserId]
if not Data then
return
end
for i,PT in pairs(Data) do
local Location,Give = Data.ToolLocation,Data.Give
if Location and Give then
table.insert(Tools,1,Tool)
end
end
GiveTools(Tools,player)
end
game.Players.PlayerAdded:Connect(function(player)
Check(player)
player.CharacterAdded:Connect(function()
Check(player)
end)
end)
1 Like