Hola, in the following code I intend it to be giving a gear:
local SpeedGearId = 99119158
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local backpack
while not backpack do
backpack = character:FindFirstChild("Backpack")
task.wait()
end
local speedGear = Instance.new("Tool")
speedGear.Parent = backpack
speedGear:Clone(workspace:WaitForChild("SpeedGearTemplate")):Parent(speedGear)
end)
Thereâs a couple of things thatâs preventing it from working
It never gets past the while not backpack do loop because itâs looking for the Backpack inside of the Character model, which doesnât exist. As a result, the backpack variable remains nil, which causes it to continue running in a loop forever. The Backpack can be found when referencing that folder within the Player object, through Player.Backpack.
However, even after that is corrected, SpeedGearId is never referenced during the code, which means that when you create a clone of a newly created tool, nothing exists within that tool. Unless of course the SpeedGearTemplate that is referenced is the Handle of the Speed Coil gear, in which case it would make more sense to place that directly into a Tool while editing the game, and then create a clone of that (which is part of the example solution that Iâll explain below).
If youâre referring to the Speed Coil item uploaded by Roblox, you would need to insert it into the game via InsertService:LoadAsset(). Although Iâd recommend inserting it via the command bar while editing the game so it doesnât have to repeatedly do this during runtime. Then, you could just create a clone of that item, similar to what the code is already doing, and then place it into the playerâs Backpack.
Steps to fix it
First, youâd run the following in Roblox Studioâs Command Bar to insert the gear into the ReplicatedStorage
(Note: I am pretty sure that anything that is added into the game via InsertService:LoadAsset() is placed into a Model, so if you canât find it, open up any newly created Models that were placed there).
-- Code to be run in the Roblox Studio Command Bar
local InsertService = game:GetService("InsertService")
local SpeedGearId = 99119158
local newlyCreatedGear = InsertService:LoadAsset(SpeedGearId)
newlyCreatedGear.Parent = game:GetService("ReplicatedStorage")
-- This adds the item into the game, placing it into the ReplicatedStorage
-- Make sure to take it out of the Model afterwards so it's just the Tool itself
After that, you can do something pretty similar to what was in the original codeblock, except youâd create a clone of the Speed Coil within the ReplicatedStorage, reference Player.Backpack, and then place that item there.
Alternatively, if you want this to be given to every player, every single time their character respawns, you can place it in their StarterGear folder. But if thatâs the case, you might as well place it directly into the StarterPack, which would accomplish the same thing without any code. However, if you still want to accomplish this through a Script, the following code would be placed into a Server Script that preferably goes somewhere such as the ServerScriptService:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpeedCoil = ReplicatedStorage:FindFirstChild("SpeedCoil") -- Adjust this to the actual name of the gear as it appears in the Explorer
local createNewSpeedCoilOnRespawn = false
-- Set this to true if you want it to give a new Speed Coil every respawn
-- This'll basically just determine if it goes in the Backpack or StarterGear
Players.PlayerAdded:Connect(function(player)
local Backpack = player:WaitForChild("Backpack")
local clonedSpeedCoil = SpeedCoil:Clone()
clonedSpeedCoil.Parent = Backpack
if createNewSpeedCoilOnRespawn == true then
local StarterGear = player:WaitForChild("StarterGear")
local newestClonedSpeedCoil = SpeedCoil:Clone()
newestClonedSpeedCoil.Parent = StarterGear
end
end)
If you have any questions about any of this, feel free to ask!
That error is indicating that what the SpeedCoil variable was referencing is nil (meaning it couldnât find an object with that name), so once it tried to create a clone of it, it errored since it cannot clone something that doesnât exist.
If the name of the object in the ReplicatedStorage is not exactly âSpeedCoilâ, make sure you update how the SpeedCoil variable on line #4 of the Script looks for the object.
So if it was named âspeedcoilâ, it would become:
local SpeedCoil = ReplicatedStorage:FindFirstChild("speedcoil")
Or, if it had a space in its name, like âspeed coilâ, it would become:
local SpeedCoil = ReplicatedStorage:FindFirstChild("speed coil")
Same thing applies for the letters that are capitalized. So, if itâs in all caps, like âSPEED COILâ, it would become:
local SpeedCoil = ReplicatedStorage:FindFirstChild("SPEED COIL")
It is case-sensitive, which means that it must be spelled and capitalized in the exact same way as the name appears when viewing the object in the Explorer.
The gear ID is 99119158 and its called âSpeed Coilâ but im still getting that error. Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpeedCoil = ReplicatedStorage:FindFirstChild("Speed Coil") -- Adjust this to the actual name of the gear as it appears in the Explorer
local createNewSpeedCoilOnRespawn = true
-- Set this to true if you want it to give a new Speed Coil every respawn
-- This'll basically just determine if it goes in the Backpack or StarterGear
Players.PlayerAdded:Connect(function(player)
local Backpack = player:WaitForChild("Backpack")
local clonedSpeedCoil = SpeedCoil:Clone()
clonedSpeedCoil.Parent = Backpack
if createNewSpeedCoilOnRespawn == true then
local StarterGear = player:WaitForChild("StarterGear")
local newestClonedSpeedCoil = SpeedCoil:Clone()
newestClonedSpeedCoil.Parent = StarterGear
end
end)```
If possible, please share a screenshot of how it appears in the Explorer while editing the game. As long as it was placed in the correct spot and the spelling and capitalization matches up with the code in the Script, that error shouldnât be happening, so there must be something else causing it to happen.
You need to take the Tool out of the Model and have it placed directly in the ReplicatedStorage.
But, since I saw that you updated the createNewSpeedCoilOnRespawn variable to true, you could have all of this handled automatically by placing it into the StarterPack, without needing to run any code from Scripts.
local SpeedGearId = 99119158
game.Players.PlayerAdded:Connect(function(player)
local character = player.Character or player.CharacterAdded:Wait()
local backpack
while not backpack do
backpack = character:FindFirstChild("Backpack")
task.wait()
end
local speedGear = Instance.new("Tool")
speedGear.Parent = backpack
local speedGearClone = speedGear:Clone()
speedGearClone.Parent = workspace:WaitForChild("SpeedGearTemplate")
end)
If you still want to handle it through the Script, move the âAcceleration Coilâ directly into the ReplicatedStorage by holding left click on it and moving it over the ReplicatedStorage. That way, itâs not placed into anything else; then when the Script tries to look for it, itâs in the exact spot itâs looking for. But if you do that, youâd need to rename it to âSpeed Coilâ or update the variable in the Script to reference âAcceleration Coilâ.
But the other option is to just move the Acceleration Coil directly into the StarterPack Service, because any Tools placed there are automatically given to players every time they respawn, which does the same thing as the Script.
I put it in replicated storage updated the script for it to be called speed coil so nothing should be called Acceleration Coil but im not getting the coil, I also found an unkown global