LocalScript not working in PlayerScripts

So i had an idea on making a localscript that gives you gear if your name matches what is in the script, but its not working. i have it in StarterPlayerScripts and it doesnt do anything or gives no errors when i play test it.
here is the localscript:

local plr = game.Players.LocalPlayer
local gears = game.ServerStorage:GetDescendants()
local userName = "Drewel112233"

if plr.Name == userName then
	for i = 1, #gears do
		if gears[i]:IsA("Tool") then
			gears[i]:Clone().Parent = plr:WaitForChild("Backpack")
			gears[i]:Clone().Parent = plr:WaitForChild("StarterGear")
		end
	end
else
	warn("there is a problem!")
end

the Warn() i put at the end doesnt ouput either.
I feel like it has something to do with where the LocalScript is at, but im not sure.

Localscripts don’t have access to ServerStorage, you’ll have to put the gears elsewhere, like in ReplicatedStorage.

well i would’ve expected an error output about that, but it gives no errors in the output window.

try putting it in starter character scripts. If that doesn’t work do what @brokenVectors said. tbh I am not the best at this type of stuff.

i just tried using Warn() in different areas of my script containing these numbers:

  • 1 (top)
  • 2 (before if)
  • 2 1/2 (in else)
  • 3 (after if)

all numbers printed except 2 1/2.

i just tried moving it into StarterCharacterScripts, still didnt work

ServerStorage can’t be accessed by the client. You’ll have to move everything over to replicatedStorage.

i moved one gear into ReplicatedStorage, and i got infinte yields on both gears[i]:Clone().Parent = plr:WaitForChild("Backpack") and gears[i]:Clone().Parent = plr:WaitForChild("StarterGear")

1 Like

Did you change gears to the descendants of replicated storage?

i did. and doing that caused it to do infinte yields.
also, an admin command model adds some folders to ReplicatedStorage. im not sure if i need to change the thing to get all children cause i know GetDescendents() gets every child in every instance, and i also dont know yet if im gonna create a folder for different types of gears to live at.

Instead of doing this in a LocalScript, I recommend using a ServerScript

game:GetService("Players").PlayerAdded:Connect(function(Player)
if Player.Name == "Drewel112233" then 
for i,v in pairs(game:GetService("ServerStorage "):GetChildren()) do if v:IsA("Tool") then v:Clone().Parent = Player.StarterPack
end
end
end)
2 Likes

If you do this on the client, no one else will see that you have the gear. You’ll have to use a Script in ServerScriptService. LocalPlayer is nil in Scripts, so you’ll have to use PlayerAdded.

it worked in a serverscript, however my main goal was trying to make this work in a LocalScript. but i dont mind that. thanks for the feedback!