Hello everyone. I making a story game and i want reset whole game when player reaches a ending. How can i do that? Im open for ideas. For example can i kick player and make rejoin to empty server? (Servers will be for only 1 player)
I donât really know how to structure the script but you can try kicking out the playing and clearing all atp services from the player. if theres like a currency or something then just clear all the atp services / datasaves that control for the storyline
i dont want kick the player because that can be cause them not rejoin, but can i kick and make rejoin automatically?
You can either do three things. Edit the players kick message to say rejoin to restart. You can kick a player and make them rejoin. or make a saves feature like botw or super mario odyssey where in the main menu you can add another save meanwhile keeping the original leaving more oppurtunitys to add more diffuculties
Yes you could just make a second place contained in your first project and it is the exact same with the other game but as itâs another place you can use TeleportService to teleport the player there without having to kick him at all.
You do not need to kick the player or teleport them. You can if you want to but you can also just add a restart button or a main menu directly in your game.
Well, how can i do that? By the way if choose this way i have to teleport them to a empty server
I tried save world as a folder in replicatedstorage and make world back load with delete the old one. But some interactions starting not work anymore
where do you keep all data? when the player reaches the ending just clear it all and respawn them back at the start
I copied all workspace and put inside a folder named âMapâ. and i put the map inside replicatedstorage. When player reaches the ending i delete all children in the workspace, copied the Map and put inside the workspace coppy of map. Until here everything is okay but when player start play again, some interactions not working anymore
you may not have copied all components of the map
Also try looping through the children of the folder and cloning them them one by one onto the workspace
Hereâs the code
ââ'lua
local button = script.Parent
local service = game:GetService(âPlayersâ)
local humanoid = service.LocalPlayer.Character:WaitForChild(âHumanoidâ)
local Players = game:GetService(âPlayersâ)
local siyahgui = game.Players.LocalPlayer.PlayerGui.gui2.policenendingsiyah
local map = game.ReplicatedStorage:WaitForChild(âMapâ)
local humanoid = game.Players.LocalPlayer.Character:WaitForChild(âHumanoidâ)
if humanoid then
print(âasdasdasdâ)
end
local sayac = 0
button.MouseButton1Click:Connect(function()
sayac += 1
if sayac == 1 then
local ReplicatedStorage = game:GetService(âReplicatedStorageâ)
local Players = game:GetService(âPlayersâ)
local function anchorCharacters(anchor, list)
for , player in pairs(Players:GetPlayers()) do
local character = player.Character
if character then
if list then
table.insert(list, character)
end
character.PrimaryPart.Anchored = anchor
end
end
end
local function loadMap(asd)
local blacklist = {}
anchorCharacters(true, blacklist)
for , child in pairs(workspace:GetChildren()) do
if not table.find(blacklist, child) then
if not child:IsA("Terrain") then
child:Destroy()
end
end
end
local clone = map:Clone()
for _, child in pairs(clone:GetChildren()) do
child.Parent = workspace
end
anchorCharacters(false)
end
loadMap()
wait(5)
humanoid.Health = 0
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Custom
siyahgui.BackgroundTransparency = 1
siyahgui.text.Text = ""
siyahgui.title.Text = ""
end
end)
âââ
if you reset the map on the client the server wont know that it has been reset
as aleks said the cloning needs to be done Server sided not from a local script
You mentioned that your game will only be singleplayer, if you set your playerlimit on 1 and use teleportservice to teleport them to the place using the placeId, roblox will automatically create a new empty server for the player.
You have to create a new place and make it unlisted so you cant join it directly only via game and then use this:
this will work perfectly as long as you donât have any progress data that saves
It would better but how can i do that really?
Itâs very simple, just kick all players, then kick new ones to let the server shut down.
function shutdownServer()
--Remove all players.
for _,player in pairs(game.Players:GetPlayers()) do
player:Kick("Server has been shutdown.")
end
--Prevent others from joining.
game.Players.PlayerAdded:Connect(function(player)
player:Kick("This server is shutting down. Join another one.")
end)
end
--Run shutdownServer() whenever you want.
As @Fimutsuu already mentioned, as long as you donât save any data, just take your placeID and use TP service like this:
Localscript:
local plr = game.Players.LocalPlayer
local tp = game:GetService("TeleportService")
local placeID = game.PlaceId
-- get a trigger, for example fire a remote event and do this on server event
tp:Teleport(placeID)
Maybe you can check if your data has saved, like this:
if dataStore:GetAsync("username") == data then
print("data already saved")
end
You can get the saved data then check if itâs equal to the data they currently have in-game.