Im making a game. And I wanna give guns out every 60 seconds and remove them every 40 seconds. Is this correct?
1 | Gun 1 = game.ServerStorage.Deagle |
2 | while true do |
3 | wait( 60 ) |
4 | Gun 1. Parent = game.Players.Player.Backpack |
5 | wait( 40 ) |
6 | Gun 1. Parent = game.ServerStorage |
7 |
8 | end |
It would be helpfull if you could correct my errors.
1) You could see if it is correct by yourself
2) For crying out loud, that script is only for a player called "Player", and if there is no player called that, it breaks.
At least, however, you showed us a script so you actually attempted to do this. Now here's one thing you should always remember: Clone()
, local
and for
are some of your best friends.
01 | while true do |
02 | wait( 60 ) |
03 | for _,player in pairs (game.Players:GetPlayers()) do --Get all current players |
04 | local GunD = game.ServerStorage.Deagle:Clone() --Make it a local variable as we're only using it here, and update it so we get a copy of it for every player. Also use only letters in variables. |
05 | GunD.Parent = player.StarterGear |
06 | end |
07 | wait( 40 ) |
08 | for _,player in pairs (game.Players:GetPlayers()) do --Get all current players, again |
09 | player.StarterGear:FindFirstChild( "Deagle" ):Destroy() --If the gun exists, remove it |
10 | player.Character:FindFirstChild( "Deagle" ):Destroy() --The gun can also be in the player's character too |
11 | end |
12 | end |