Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make all models in my roblox game world regenerate when the round restarts?

I have seen many model regeneration scripts that go by time but this is not what I want. I want a script that regenerates the models when my lobby script restarts (the lobby script I am using detects when all players have died and then teleports them out of the lobby and into the game play area).

Lobby script:

local oldMessage = ""
local minPlayers = 2
 
function teleportAllPlayers()
	local target = CFrame.new(workspace.TeleportTarget.Position)
	for i, player in ipairs(game.Players:GetChildren()) do
		player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
		player.Playing.Value = 1
		
	end
end
 
function message(message)
	if oldMessage ~= message then
		oldMessage = message
		print(message)
	end
end
 
function playersCurrentlyPlaying()
	for i, player in ipairs(game.Players:GetChildren()) do
		if player.Playing.Value == 1 then return true end
	end
	return false
end
 
game:GetService('Players').PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		character:WaitForChild("Humanoid").Died:connect(function()
			player.Playing.Value = 0
		end)
	end)
 
	local playing = Instance.new("IntValue", player)
	playing.Value = 0
	playing.Name = "Playing"
end)
 
 
while(true) do
	wait(10)
	if #game.Players:getPlayers() >= minPlayers then
		if playersCurrentlyPlaying() then
			message("Waiting for the current game to end...")
		else
			message("There are enough players for a new game!  Teleporting...")
			wait(1)
			teleportAllPlayers()
		end
	else message("Waiting for more players...") end
end

Sorry if I goofed up while asking this question, this is my first time using this website.

1 comment

0

This looks like a free model :)

1 answer

Group all of the target models and call it "Models" Copy and paste this group into ServerStorage

function reset()
	workspace.Models:Destroy()
	game.ServerStorage.Models:Clone().Parent = workspace
end

(if statement regarding whether or not all players have died) then
	reset()
end

5 comments

0

Following you so far but where exactly do I put the script? Sorry, I am really new to this, and thanks so much for the response.

0

Put the reset function with the other functions in your lobby script and put reset() after the teleporting message.

0

NARWALS NARWALS

0

SWIMMING IN THE OCEAN

0

I tried that but it didn't work... could you just give me the whole lobby script with your code in it? Again, I am a complete novice to this. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.