if been making a game that teleports players to a map and gives one player a gun the gun ticks and kills him after 30 seconds and then another gun is given to another one of the alive players. tho it doesnt work it says time “exhausted” and everything me and my friend have tried so far hasnt worked right now it just waits a bunch of time then tps players while giving errors and keeps giving players guns
please help
local rep = game:GetService("ReplicatedStorage")
local Lobby = game.Workspace.Lobby
local Maps = rep.Maps:GetChildren()
local status = rep.Status
local rev = rep.Rev
local gunIsActive = nil
local event = rep.Events.AliveCheck
local availablePlayers = {}
local everyoneIsReady = true
local playercount = game.ServerStorage.Playercount
wait(2)
repeat
print("waiting for players" ..playercount.Value)
wait(1)
until playercount.Value > 1
while everyoneIsReady == true and playercount.Value > 1 do
for i = 10, 0, -1 do
status.Value = "Intermission: " .. i
task.wait(1)
end
local ChosenMap = Maps[math.random(1, #Maps)]
print(ChosenMap)
local CloneMap = ChosenMap:Clone()
CloneMap.Parent = game.Workspace
status.Value = "Next map: ".. ChosenMap.Name
task.wait(3)
for i, pluh in pairs(game.Players:GetPlayers()) do
local char = pluh.Character
if char then
local HumP = char.HumanoidRootPart
print("got HUMP")
HumP.CFrame = CloneMap.TpPoint.CFrame
pluh.Backpack.PlayerStatus.Value = "Alive"
table.insert(availablePlayers, pluh)
print(availablePlayers)
end
end
while #availablePlayers >= 1 do
repeat
local ChosenPlayer = availablePlayers[math.random(1, #availablePlayers)]
print(availablePlayers)
gunIsActive = ChosenPlayer.Name
rev:Clone().Parent = ChosenPlayer.Character
wait()
until ChosenPlayer.Backpack.PlayerStatus == "Dead"
end
gunIsActive = nil
ChosenMap = nil
end
event.OnServerEvent:Connect(function(player, stat)
if player.stat == "Dead" then
table.remove(availablePlayers, player)
print(player)
end
end)
all the Print checks are working i really dont know what is not working you just wait an apsurd time then it does what the for loop does at the same time with the while loop and while loop keeps repeating until i turn it off
UPDATE i added a wait() on the first for loop and that tps the players and then gives the gun and tps them back at the same space indefenetly while saying another script that wasnt problematic before after that it prints the player list indefenetly every 0.1 seconds
For the last photo, try slowing down your script. You have too many events happening at the same time. I am new to coding too, but I had a similar issue with the last photo there with the execution time. Just add delays between important things and that should fix that. Try changing the isntActive loop to something like this:
while isntActive == true do
if script.Parent.Parent == rep then
isntActive = false
wait(1)
end
end
I did change that script i added a wait() to both and that seems to fix one of the bugs but now it just inf repeats mains scripts repeat until function
If the round system is all in one script, put a while true do loop inside, if you haven’t. You could also had a boolValue in replicated storage that is named RoundActive and update it to true and teleports players to the map when there is a round in progress, and when it turns false teleports the players back to the lobby.