Template saving with a PlayerRemoving event

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve a saving system of my building template when a player is disconnected/leaves.

  2. What is the issue? Include screenshots / videos if possible!
    The table that contains children returns nil even though it should return objects

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have talked to multiple people, no clear answers, also looked through the forum without any clear answer on workspace ‘unloading’

This is the code that I have written.

local RS = game:GetService('ReplicatedStorage')
local ST = RS:WaitForChild('RemEVent'):FindFirstChild('SaveTemplateBind')
local players = game:GetService('Players')

players.PlayerRemoving:Connect(function(player)
	local TemplateSave = {

	}
	for _,placedasset_folder in pairs(workspace.LevelTemplate.ActiveAssets.PlacedAssets:GetChildren()) do
		print(placedasset_folder)
		local ARP = placedasset_folder:FindFirstChild('AssetRootPart',true)
		local cframe = {ARP.CFrame:GetComponents()}
		table.insert(TemplateSave,{cframe,placedasset_folder.name})
	end
	print(TemplateSave)
	ST:Fire(player,TemplateSave)
end)

ST is bindable event that sends the template and the player to another serverscript that handles the datastore for this template.

This script is also located in ServerScriptService by the way.

1 Like

It seems like it should work fine assuming SaveTemplate bind does what you want.

1 Like

yes it does what i want, it sends a proper signal, but when printing TemplateSave and placedasset_folder, TemplateSave is empty and placedasset_folder is printing nil