You're using wait(30) which delays 30 seconds for EACH loop.
This is why only one person got the sword (You have to wait 30 seconds until one person's sword is destroyed and another person receives it). Everything else is correct and there's no problem. You have to put the wait() function outside the loop then you have to create another loop to find the player's sword and delete them AFTER the wait() function.
You probably want to fit 2 functions inside 1 function if you're going to activate 1st function and wait 30 seconds before you activate 2nd function. Fixed code (Solution) will activate the initial function swordfight() that activate givesword() function then wait for 30 seconds before activate destroysword() function.
== Here's the solution ==
local function givesword()
for i, v in pairs (game.Players:GetPlayers()) do
wait()
local linked = game.ServerStorage.sword:Clone()
linked.Parent = v.Backpack
end
end
local function destroysword()
for i, v in pairs (game.Players:GetPlayers()) do
wait()
local sword = v.BackPack.sword or game.Workspace:FindFirstChild(v.Name).sword
sword:Destroy()
end
end
local function swordfight()
givesword()
wait(30)
destroysword()
end
swordfight()
In the future, you probably want to check if there's a function that delays the loop. All code inside the for loop will execute itself several times depending on the loop. For example, you can execute the loop 12 times (12 players) and you have to wait like 900 seconds for the last person to receive the sword.
Happy Scripting!
2 comments
Problem is he want to give sword to everyone and then destroy sword from everyone after 30 seconds by looking at the code.
oh