Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I give players tools when they spawn?

So this is my tool give to players when they spawn (it randomizes). How do I make it where it gives it to the player when they join the game? It doesn't give it to them at all when they first join.

game.Players.PlayerAdded:connect(function(p) 	
p.CharacterAdded:connect(function(c) 
repeat 
wait() 
until p:FindFirstChild("Backpack") 
local clone = game.Lighting.WEAPONS:GetChildren()[math.random(1, #game.Lighting.WEAPONS:GetChildren())]:clone()
clone.Parent = p.Backpack 
c:WaitForChild("1").Value = clone.Name
end) 
wait(2)
end) 

1 answer

✓ Accepted answer
local weapons = game.ReplicatedStorage.Weapons
function findRandomChild(model)
	if #model:GetChildren() ~= 0 then
		local children = model:GetChildren()
		local child = children[math.random(1,#children)]
		return child
	end
end
game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		local weapon = findRandomChild(weapons)
		plr:WaitForChild('Backpack', 10000)
		weapon:Clone().Parent = plr.Backpack
	end)
end)

Try this.

This discussion is preserved as it was. New answers, comments, and votes are closed.