Fairly new scripter here,
I have a script here that gives you a random gear on spawn. I’m not sure how to make it give you multiple gears and there’s not really any tutorials on this. How can you modify the script below to make it grant you 2 gears?
local HttpService = game:GetService("HttpService")
local InsertService = game:GetService("InsertService")
local worldInfo = HttpService:JSONDecode(script.Parent.WorldInfo.Value)
function giveGear(plr, gearId, gearGiverId)
if gearGiverId then
if findGear(plr, gearGiverId) then
return
end
end
if gearId then
local model = InsertService:LoadAsset(gearId)
local tool = model:FindFirstChildOfClass("Tool")
tool.CanBeDropped = (worldInfo.AllowDropping and tool.CanBeDropped) or worldInfo.AllowDropping
tool.Parent = plr.Backpack
if gearGiverId then
local gearGiverIdValue = Instance.new("StringValue")
gearGiverIdValue.Name = "GearGiverId"
gearGiverIdValue.Value = gearGiverId
gearGiverIdValue.Parent = tool
end
model:Destroy()
end
end
script.GiveGear.OnInvoke = giveGear
function findGear(plr, gearGiverId)
for _, gear in pairs({plr.Character:FindFirstChildOfClass("Tool"), unpack(plr.Backpack:GetChildren())}) do
if gear:FindFirstChild("GearGiverId") and gear.GearGiverId.Value == gearGiverId then
return gear
end
end
end
script.FindGear.OnInvoke = findGear
function giveGears(plr, gearsList)
for _, gearId in pairs(gearsList) do
giveGear(plr, gearId)
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if worldInfo.Gears then
giveGears(plr, worldInfo.Gears)
end
if plr.Team then
if worldInfo.TeamGears then
local teamGears = worldInfo.TeamGears[plr.Team.Name]
if teamGears then
giveGears(plr, teamGears)
end
end
end
end)
end)