I was making a sword giving script by finding all children of game.Players, but nothing happens when the script runs. (No errors either.) My script is as follows:
local part = script.Parent
local children = game.Players:GetChildren()
script.Parent.ClickDetector.MouseClick:Connect(function(plrwhoclicked)
local Humanoid = plrwhoclicked.Character:FindFirstChild("Humanoid")
if Humanoid then
for i = 1, #children do
local sword = game.ReplicatedStorage.Sword:Clone()
sword.Parent = children.Backpack[i]
end
end
end)
local part = script.Parent
script.Parent.ClickDetector.MouseClick:Connect(function(plrwhoclicked)
local Humanoid = plrwhoclicked.Character:FindFirstChild("Humanoid")
if Humanoid then
for i = 1, #game.Players:GetChildren() do
local sword = game.ReplicatedStorage.Sword:Clone()
sword.Parent = game.Players:GetChildren()[i].Backpack
end
end
end)
The post above by Aleh should work.
The reason your original code is because of the following line: local children = game.Players:GetChildren()
You only set this once at the very beginning of your game, so that no players have time to join. Without any players it won’t run correctly