I made a script in which it clones gamepass tools if the player owns a gamepass, but it’s duplicating the tools twice, I tried looking through the developer forum, but nothing seems to be working.
local mps = game:GetService("MarketplaceService")
local passFolder = game:GetService("ServerStorage"):WaitForChild("GamepassFolder")
local freeTools = {"R0TT3DC0RVSES"}
local function findPlr(plr)
for i,v in pairs(freeTools) do
if v == plr then
return true
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
for _, v in pairs(passFolder:GetChildren()) do
if mps:UserOwnsGamePassAsync(plr.UserId, v.ID.Value) or findPlr(plr.Name) then
for i,x in pairs(v:GetChildren()) do
if x:IsA("Tool") then
if plr.Backpack:FindFirstChild(x) then
return nil
else
x:Clone().Parent = plr.Backpack
end
end
end
end
end
end)
end)
probaly its because u have a tool data store, a think that you can do is:
Before your clone and parents the tool for the player inventory, check if have another one, if dont have you clone and put it on the player inventory else u dont put in the player inventory
you can probably add break so the loop only runs once, so if you want to run it again, turn it into a function
function GiveTool()
for i,x in pairs(passFolder:GetChildren()) do
if x:IsA("Tool") then
x:Clone().Parent = plr.Backpack
break
end
end
end
plr.CharacterAdded:Connect(function(char)
for _, v in pairs(passFolder:GetChildren()) do
if mps:UserOwnsGamePassAsync(plr.UserId, v.ID.Value) or findPlr(plr.Name) then
GiveTool()
end
end
end)