Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I give all players an item at a certain time?

Asked by 8 years ago
Edited by OldPalHappy 8 years ago

I have this script, but it only works when I test it, and not in the real game...

1while true do
2    wait(27)
3    game.ServerStorage["LinkedSword"]:Clone().Parent = game.Players.LocalPlayer.Backpack
4    wait(58)
5end

Please help! I've looked everywhere but I get the same answer, and it never works!

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

Please use code block in the future

Your problem is most likely that you are attempting to index the LocalPlayer from a server script.

Try parenting this code into StarterPack from a LocalScript and it should work.

But note - it will make duplicate swords so you should probably add a check. And localscripts can't access ServerStorage so would need to put the tool in ReplicatedStorage

01local sword = game.ReplicatedStorage["Linked Sword"];
02local plr = game.Players.LocalPlayer;
03 
04while true do
05    wait(27)
06    if not plr.Backpack:FindFirstChild(sword.Name) then
07        sword:Clone().Parent = plr.Backpack;
08    end
09    wait(58)
10end

Alternatively, if you want the whole server to recieve swords at the same time, you can use a generic for loop and iterate through the players from a script in Workspace.

01local sword = game.ServerStorage["Linked Sword"];
02 
03while true do
04    wait(27)
05    for _,v in next,game.Players:GetPlayers() do
06        if not v.Backpack:FindFirstChild(sword.Name) then
07            sword:Clone().Parent = v.Backpack;
08        end
09    end
10    wait(58)
11end
Ad

Answer this question