for _, player in pairs(game.Players:GetChildren()) do
game.ReplicatedStorage.ClassicSword:Clone()
game.ReplicatedStorage.ClassicSword:Clone()
game.ReplicatedStorage.ClassicSword.Parent = player.Backpack
game.ReplicatedStorage.ClassicSword.Parent = player.StarterPack
end
I assume that at the time the script executes, it is not, that’s why I suggest to do the following:
for _, player in pairs(game.Players:GetChildren()) do
local sword = game.ReplicatedStorage.ClassicSword:Clone()
sword.Parent = player.Backpack
sword = game.ReplicatedStorage.ClassicSword:Clone()
sword.Parent = player.StarterPack
end
I fixed the problem in your script, becuase you were changing the parent not of the ClassicSword copy but the original one.
Use :WaitForChild("ClassicSword") instead of just .ClassicSword the game assets don’t load in right away you know.
Right when this script runs there won’t be any players in the game yet, so when the script loops through all the players and gives all of them swords, there won’t be any players to get them. What you’d have to do is use PlayerAdded to detect whenever anyone joins the game and then give them the sword.
game.Players.PlayerAdded:Connect(function(Player)
local ClassicSword = game.ReplicatedStorage:WaitForChild( "ClassicSword"):Clone()
ClassicSword.Parent = Player.Backpack
end)
I’m not really sure what you’re trying to do with that line. StarterPack isn’t a valid member of player, it seems pretty random.
There’s a much easier way to do this though, you can just put ClassicSword in StarterPack, and the game will automatically give it to everyone when they join.
The problem is not that he has to wait for the sword, because it’s in replicated storage when the game starts, the problem was that he was changing the parent of the original sword in replicated storage, not the copied one.
The game’s assets many times load in after the scripts start running. This is most likely the problem, but there is another problem that needs to be fixed.
for _, player in pairs(game.Players:GetChildren()) do
local sword = player.Backpack.ClassicSword
local sword2 = player.StarterGear.ClassicSword
sword.Parent = game.ReplicatedStorage
sword2.Parent = game.ReplicatedStorage
end
for _, player in pairs(game.Players:GetChildren()) do
local sword = player.Backpack:FindFirstChild("ClassicSword")
local sword2 = player.StarterGear:FindFirstChild("ClassicSword")
if sword then sword:Destroy() end
if sword2 then sword2:Destroy() end
end
Yes because that’s how Roblox works, an equipeed item is moved to the Player’s character, you will have to look for the sword inside of the character too and remove it from there if it exists.