Hello, the thing I want help with might be a little confusing on why I would want that. It has something to do with an obby, and teamwork. If a player dies the whole obby restarts, but if they all make it the game restarts. They have about 7 minutes to complete it.
I just don’t know how to do it, and I really hope to get what I want, this project I’m making is fun and I want to complete it.
I did try fighting some answers, but there was not something I wanted. Thank you!
You can use a value and set it to true when the obby/game is on. And if a player dies, the script can check if the value is true. If the value is true, the entire game resets.
You can store this value somewhere in the workspace as it should be in the server, and not in the client of the game.
Let me know if you still need help or more detail!
Your game sounds interesting and I’d like to play it.
So how can you do it? Well, loop through the player list and use Humanoid.Died to check if the player died. If any player dies during the round, end the round.
for _, player in pairs(game.Players:GetService("Players"):GetPlayers() do
player.Character.Humanoid.Died:Connect(function()
-- reset the obby
end)
end
If you’re using the value like I said, just set it to true when the game starts and input it inside the script attached. Once the game ends, just set it to false. Make sure it is a server script.
Im going to check it out right now, I actually also had the for loop part to kill the players, but didn’t know it would work! (for something else though)
You’re welcome! Instead of using a value such as a BoolValue, create a variable called isGameRunning instead and set it to true when the round is in progress.
I made simple round system. I don’t know if that’s what you meant.
I hope that will help you.
-- Example Code --
local t = 1 -- time
local gameStopped = false -- this variable is needed, because we will checking if round is still running or not
local MaxRoundTime = 60 -- Your round time (default: 1 minute)
function StopRound()
-- code to reset round
print("Round stopped!")
end
function onCharacterAdded(char)
local humanoid = char:WaitForChild("Humanoid") -- waiting for humanoid to load
if not humanoid then return end -- if humanoid doesn't existed then stop all script
repeat
print(t)
t = t + 1
wait(1)
humanoid.Died:Connect(function() -- fires when player dies
gameStopped = true
StopRound() -- calling function with code to reset round
t = MaxRoundTime -- basically breaking loop
end)
until t == MaxRoundTime
if not gameStopped then -- checking if game wasn't stop when player dies
StopRound() -- calling function again
end
-- reseting game
gameStopped = false
t = 1
end
function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded) -- getting character
end
game.Players.PlayerAdded:Connect(onPlayerAdded) -- getting player
I know I said ill be here tomorrow, but this really worked and helped me out too. Thank toy so much! I just added part I need into what happened, again thanks!