Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Why doesn't this line of code clone a sword into a player's starter gear?

Asked by 10 years ago
game.ServerStorage.Sword:Clone().Parent = game.Players:GetPlayerFromCharacter(part.Parent):WaitForChild("StarterGear")
0
Its Backpack not startergear. Thetacah 712 — 10y

1 answer

Log in to vote
1
Answered by
Thetacah 712 Moderation Voter
10 years ago

No such thing as a StarterGear, its called a Backpack. I find your code looks cleaner if you put that code in two lines. Basically, you make a variable, then Parent it. That's up to you, though. Keep in mind, this script would only work if it's in a .Touched function and the parameter is called part.

Also, something else to keep in mind is that you **cannot **access ServerStoragethrough a localscriptsince it's only accessible through the server. In this case, you can use ServerStorage as you aren't using a localscript

game.ServerStorage.Sword:Clone().Parent = game.Players:GetPlayerFromCharacter(part.Parent):WaitForChild("Backpack")

--My way

local clone = game.ServerStorage.Sword:Clone()
clone.Parent = game.Players:GetPlayerFromCharacter(part.Parent):WaitForChild("Backpack")
0
Actually, it is a .Touched with part. I was just showing you a snippet. Thanks for the help! dirty_catheter 7 — 10y
Ad

Answer this question