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
Main = require(game.Workspace.ModuleScripts.Main) local status = game.ReplicatedStorage:WaitForChild("Status") local intermissionTime = 60 local roundTime = 120 local players = game.Players:GetPlayers() local playerService = game.Players local Number = intermissionTime local sword = game.ServerStorage.Swords.BasicSword while true do for i = 1, intermissionTime, 1 do -- Countdown for intermission time status.Value = "INTERMISSION (" .. Number .. ")" wait(1) Number = Number - 1 end Number = roundTime Main.ToBattleMap() for i = 1, #players do -- Attempting to clone and parent the clone to the player's backpack local player = players[i] player.CharacterAdded:Connect(function(Player) local backpack = player:WaitForChild("Backpack") local swordClone = sword:Clone() swordClone.Parent = backpack end) end for i = 1, roundTime, 1 do -- Countdown for Round Time status.Value = "ROUND IN PROGRESS (" .. Number .. ")" wait(1) Number = Number - 1 end Main.ToLobbyMap() Number = intermissionTime end
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:
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!
local time = 0 local plrs = game.Players:GetChildren() local plr = plrs math.random(1,#plrs) for p = 1,#plrs do time = 120 game.ReplicatedStorage.Sword.Parent = plrs[p].Backpack repeat time = time - 1 wait(1) until time == 0