Hello so i wrote a code to search for player's backpack if the specific gear is in…
- User
Hello so i wrote a code to search for player's backpack if the specific gear is in player's backpack its gonna put it in the startergear but i forgot to search for player bacpack could you fix it?local gearStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") print("debug") local specificGearNames = { "KnightSword", "GrimAxe" } print("debug2") local function onGearObtained(player, gear) for i, v in ipairs(specificGearNames) do print(i, v) -- Accessing StarterGear from Server Script local function onPlayerAdded(player) -- Wait for the StarterGear to be added local starterGear = player:WaitForChild("StarterGear") -- Add a Tool to the StarterGear local gears = gearStorage.SpecificGears.GrimAxe:Clone() gears.Parent = starterGear end Players.PlayerAdded:Connect(onPlayerAdded) end end onGearObtained()
- Assistant
Sure, here is the fixed code:
local gearStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") print("debug") local specificGearNames = { "KnightSword", "GrimAxe" } print("debug2") local function onGearObtained(player, gear) for i, v in ipairs(specificGearNames) do print(i, v) local function onPlayerAdded(player) -- Wait for the Backpack to be added local backpack = player:WaitForChild("Backpack") -- Check if the gear is in the player's backpack local gearInBackpack = backpack:FindFirstChild(v) if gearInBackpack then -- Access StarterGear from Server Script local starterGear = player:WaitForChild("StarterGear") -- Add gear to StarterGear local gearClone = gearStorage.SpecificGears[v]:Clone() gearClone.Parent = starterGear end end -- Connect the event once for each specific gear Players.PlayerAdded:Connect(onPlayerAdded) end end onGearObtained()Note: Make sure that the gear items you want to check for exist in the
"SpecificGears"folder ofgearStorage.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.