hey what variable i should use to call all of the mentioned gears in this script:local…
- User
hey what variable i should use to call all of the mentioned gears in this script:local specificGearNames = { "KnightSword", "GrimAxe" }
local function onGearObtained(player, gear) --Check if the obtained gear is one of the specific gears for _, gearName in ipairs(specificGearNames) do if gear.Name == gearName then --Find the StarterGear folder for the player local function onPlayerAdded(player) -- Wait for the StarterGear to be added local starterGear = player:WaitForChild("StarterGear") --Move the obtained gear to the StarterGear folder local gears = specificGearNames.Clone() gears.Parent = starterGear end break end end end
--Determine when a player obtains a gear game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character.ChildAdded:Connect(function(child) if child:IsA("Tool") then onGearObtained(player, child) end end) end) end)
- Assistant
To call all the mentioned gears in this script, you can use the variable "specificGearNames". This variable is an array that contains the names of the specific gears you want to check for.
- User
can i use “specificGearNames” to clone them?
- Assistant
No, you cannot use the variable "specificGearNames" directly to clone the gears. The variable "specificGearNames" is just an array that contains the names of the specific gears. To clone the gears, you would need to access the actual gear objects either by using their names or by storing the gear objects themselves in a separate table. Once you have the gear object, you can clone it using the "Clone()" method.
- User
can i use the serverstorage as table?
- Assistant
Yes, you can use ServerStorage as a table to store the gear objects. Here's an updated version of the script using ServerStorage as a table to store the gear objects:
local gearStorage = game:GetService("ServerStorage") local specificGearNames = { "KnightSword", "GrimAxe" } local function onGearObtained(player, gear) -- Check if the obtained gear is one of the specific gears for _, gearName in ipairs(specificGearNames) do if gear.Name == gearName then -- Move the obtained gear to the ServerStorage/SpecificGears folder local specificGearsFolder = gearStorage:FindFirstChild("SpecificGears") if not specificGearsFolder then specificGearsFolder = Instance.new("Folder") specificGearsFolder.Name = "SpecificGears" specificGearsFolder.Parent = gearStorage end gear.Parent = specificGearsFolder break end end end -- Determine when a player obtains a gear game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character.ChildAdded:Connect(function(child) if child:IsA("Tool") then onGearObtained(player, child) end end) end) end)In this updated script, we create a table called
specificGearNamesto hold the gear names. When a gear is obtained, we check if its name matches any of the names inspecificGearNames. If it does, we move the gear object to a folder called "SpecificGears" inside ServerStorage. If the "SpecificGears" folder doesn't exist, we create one first. - User
so i use the “SpecificGears” gears to clone multiple gears right?
- Assistant
Yes, that's correct. The "SpecificGears" folder inside ServerStorage can be used to store the specific gears that you want to clone. You can add multiple gear objects to the "SpecificGears" folder, and then clone them as needed.
Here's an example of how you can clone the gears stored in the "SpecificGears" folder:
-- Find the SpecificGears folder in ServerStorage local specificGearsFolder = gearStorage:FindFirstChild("SpecificGears") -- Check if the SpecificGears folder exists if specificGearsFolder then -- Clone all the gears inside the SpecificGears folder for _, gear in ipairs(specificGearsFolder:GetChildren()) do local clonedGear = gear:Clone() -- Do something with the cloned gear (e.g., give it to the player) end endIn this example, we first check if the "SpecificGears" folder exists in ServerStorage. If it does, we loop through all the gear objects inside that folder using the
GetChildren()method. Then, we clone each gear using theClone()method and can perform any desired actions with the cloned gear object (e.g., give it to the player). - User
did i do it correct:local gearStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") local specificGearNames = { "KnightSword", "GrimAxe" }
local function onGearObtained(player, gear) --Check if the obtained gear is one of the specific gears for _, gearName in ipairs(specificGearNames) do if gear.Name == gearName then --Move the obtained gear to the ServerStorage/SpecificGears folder local specificGearsFolder = gearStorage:FindFirstChild("SpecificGears") -- 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 clonedgears = specificGearsFolder:Clone() clonedgears.Parent = starterGear specificGearsFolder.Parent = gearStorage gear.Parent = specificGearsFolder end Players.PlayerAdded:Connect(onPlayerAdded) break end end end
--Determine when a player obtains a gear game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character.ChildAdded:Connect(function(child) if child:IsA("Tool") then onGearObtained(player, child) end end) end) end)
- Assistant
Your script looks mostly correct, but there are a few issues:
-
You don't need to redefine
Playersas you have already obtained the Players service usinggame:GetService("Players"). -
The
onPlayerAddedfunction is defined inside theonGearObtainedfunction, which can cause issues. Move theonPlayerAddedfunction outside of theonGearObtainedfunction. -
In the
onPlayerAddedfunction, you should connect to theplayerargument passed to the function instead of connecting toPlayers.PlayerAdded. ReplacePlayers.PlayerAdded:Connect(onPlayerAdded)withplayer.CharacterAdded:Connect(onPlayerAdded). -
The line
specificGearsFolder.Parent = gearStorageis unnecessary sincespecificGearsFolderis already created as a child ofgearStoragewhen you clone it into the StarterGear.
Here's the modified version of your script:
local gearStorage = game:GetService("ServerStorage") local Players = game:GetService("Players") local specificGearNames = { "KnightSword", "GrimAxe" } local function onGearObtained(player, gear) -- Check if the obtained gear is one of the specific gears for _, gearName in ipairs(specificGearNames) do if gear.Name == gearName then -- Move the obtained gear to the ServerStorage/SpecificGears folder local specificGearsFolder = gearStorage:FindFirstChild("SpecificGears") -- 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 clonedGears = specificGearsFolder:Clone() clonedGears.Parent = starterGear gear.Parent = specificGearsFolder end player.CharacterAdded:Connect(onPlayerAdded) break end end end -- Determine when a player obtains a gear game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) character.ChildAdded:Connect(function(child) if child:IsA("Tool") then onGearObtained(player, child) end end) end) end)Make sure to test the script thoroughly to ensure it behaves as expected.
-