im making a rounds system where if the timer runs out the round ends and if there’s no survivors left or if the killer disapears then the round ends.
the timer ending the round works just fine, its just that killing all the survivors doesn’t end the round.
my code
spawn(function()
while true do
wait()
local players = game:GetService("Players"):GetPlayers()
survivorcount = 0
killercount = 0
for _, player in pairs(players) do
wait()
if player.Character.killer.Value == true then
killercount = killercount + 1
end
if player.Character.survivor.Value == true then
survivorcount = survivorcount + 1
end
end
wait(0.1)
if survivorcount == 0 or killercount == 0 then
if workspace.inRound.Value == true then
script.Parent.Time.Value = 40
local players = game:GetService("Players"):GetPlayers()
for _, player in pairs(players) do
if player.Character.killer.Value == true then
player.Character:Destroy()
player:LoadCharacter()
end
if player.Character.survivor.Value == true then
player.Character:Destroy()
player:LoadCharacter()
end
end
end
survivorcount = 0
killercount = 0
workspace.inRound.Value = false
end
end
end)
its not the full code but its the part thats not working.
1 Like
Hello
add --!strict and --!native to the script and try again
where? you can’t tell me what to add and not tell me where to add it
the script is 37 lines long bro.
At the very top, line 1 and maybe line 2 for the other script, man people just refuse to actually explain stuff nowadays :d. Also I don’t think any of those would actually help your problem
yeah, idk, it does the thing when i try one player and go into the match because theres no survivors it ends it immedietly but when i have survivors in the match and I kill all the survivors it doesn’t end the match, I tried setting the survivor values for them to false but it just still won’t work.
Your while true do loop runs constantly. When a survivor is killed, their character is deleted. The loop immediately runs again and tries to check player.Character.survivor.Value for that same player. Since their character no longer exists (player.Character is nil), the script errors and stops running.
Because you’re using spawn(function()), this error happens silently without printing to the output, so you never know it crashed. The loop simply dies, and your round gets stuck.
spawn(function()
while true do
wait()
local players = game:GetService("Players"):GetPlayers()
local survivorcount = 0
local killercount = 0
for _, player in pairs(players) do
if player.Character then
if player.Character:FindFirstChild("killer") and player.Character.killer.Value == true then
killercount = killercount + 1
end
if player.Character:FindFirstChild("survivor") and player.Character.survivor.Value == true then
survivorcount = survivorcount + 1
end
end
end
if (survivorcount == 0 or killercount == 0) and workspace.inRound.Value == true then
workspace.inRound.Value = false
script.Parent.Time.Value = 40
for _, player in pairs(players) do
if player.Character then
if player.Character:FindFirstChild("killer") and player.Character.killer.Value == true then
player:LoadCharacter()
end
if player.Character:FindFirstChild("survivor") and player.Character.survivor.Value == true then
player:LoadCharacter()
end
end
end
end
end
end)
I mean this might reveal the problem
Let me know what happens, when using this in your game.