Hello Everyone
I've been trying to create code where after an intermission time, a sword will be given to the player.
Here is a regular script (Not LocalScript) of the game loop that I made
01 | Main = require(game.Workspace.ModuleScripts.Main) |
02 | local status = game.ReplicatedStorage:WaitForChild( "Status" ) |
03 | local intermissionTime = 60 |
04 | local roundTime = 120 |
05 | local players = game.Players:GetPlayers() |
06 | local playerService = game.Players |
07 | local Number = intermissionTime |
08 |
09 | local sword = game.ServerStorage.Swords.BasicSword |
10 |
11 | while true do |
12 | for i = 1 , intermissionTime, 1 do -- Countdown for intermission time |
13 | status.Value = "INTERMISSION (" .. Number .. ")" |
14 | wait( 1 ) |
15 | Number = Number - 1 |
When I run it, The tool won't show up after the intermission time is over, but no errors are shown in the output. Can someone please tell me what is happening and how to fix this so it will show up?
Thanks in advance :)
I'm not sure if this will solve your problem, but try putting the sword in replicated storage, that is what I usually do. I also saw that in line 22 for the paramater of the function you put player with a capital P. In line 23 however, you put player with a lower case p.
I already see the issue here. When the games starts, it clears something from the ServerStorage, and it doesn't detect the item being in the ServerStorage, to prevent that from happening, you'd declare the variable by placing a duplicate of the Sword in ReplicatedStorage, but, keep the normal Sword in ServerStorage, write this code:
1 | local sword = game.ServerStorage.Swords.BasicSword or game.ReplicatedStorage.Swords.BasicSword |
That way, if the sword doesn't happen to be in ServerStorage, it automatically searches in the ReplicatedStorage.
Here you go!
01 | local time = 0 |
02 | local plrs = game.Players:GetChildren() |
03 | local plr = plrs math.random( 1 ,#plrs) |
04 | for p = 1 ,#plrs do |
05 | time = 120 |
06 | game.ReplicatedStorage.Sword.Parent = plrs [ p ] .Backpack |
07 | repeat |
08 | time = time - 1 |
09 | wait( 1 ) |
10 | until time = = 0 |