Well lets say you only want them to get a weapon when they touch a certain part:
Assuming this is a regular script inside a part:
local sword = game.serverstorage.ClassicSword
script.Parent.Touched:Connect(function(man)
local player = game.Players:FindFirstChild(man)
local dupescword = sword:Clone()
dupesword.Parent = player
end
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if player.Name == "CbrahDev" then
if msg == ":giveswords" then
for _, v in pairs(game.Players:GetDescendants()) do
if v:IsA("Player") then
game.ServerStorage.ClassicSword:Clone().Parent = v.Backpack
end
end
end
end
end)
end)
:GetPlayers() would probably be better to use in a situation like that.
But you’re on the right track, if he’s wanting to give them a weapon at a specific time then a loop over the Player’s list is probably your best bet.
if you do decide to use this make sure to fire the remote event when you want them to get the swords
fire remote event which is the: game.ReplicatedStorage:WaitForChild(“GiveSwords”):FireServer()
I think you’re misunderstanding the question and the solution, for one the topic is how to give all players a weapon at a specific time not just an individual. Therefor looping over the Player’s list is in-fact ideal; however I don’t think the original post creator is wanting it to be a command; he should just make a simple function
local function GiveWeapon()
for i,v in pairs(game.Players:GetPlayers()) do
game.ServerStorage.ClassicSword:Clone().Parent = v.Backpack;
end
end
and just do GiveWeapon() when he wants to give the players a weapon
local function GiveSword()
wait()
for _, Players in pairs(game.Players:GetChildren()) do
local characters = workspace[Players.Name]
if characters:FindFirstChild("ClassicSword") then
else
script.ClassicSword:Clone().Parent = characters
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(Character)
wait(5)
GiveSword()
end)
end)
as the man above me has stated(very handsome btw) you should just use a function
i remade his function and came up with this. oh and make sure the swords parent is the script or just change the script.ClassicSword to wherever the sword is, and obviously replace where the GiveSword() goes
No where does he state he wants to give the weapon on spawn. He says “When I want it to”; if he wanted the person to spawn with a sword he wouldn’t even need a script to do so, he could just put it in the starter gear section in studio and it would handle it automatically. I will grant you that his example code uses PlayerAdded tho which makes both the question and the example very misleading so maybe some clarification is needed.