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

What is the error in this script?

Hi, I'm having a problem with this code.

I'm testing on saving parts using Data Stores, but when I start a server and start a new player into the server, the output returns an error that I believe has been already fixed.

This picture is what the output returned.

This picture displays the hierarchy of the Explorer.

Note: There is just a bunch of parts inside the model that is inside the ServerStorage.

Do you know the solution to fix the error?

StructureStore = game:GetService("DataStoreService"):GetDataStore("StructureStore")
local structure = game:GetService("ServerStorage"):FindFirstChild("Structure_Player")

function PlayerEntered(player)
	local key = "Structure_"..player.Name
	repeat wait() until player.Character
	
	if StructureStore:GetAsync(key) ~= nil then
		StructureStore:GetAsync(key).Parent = game.Workspace
	else
		local structure_clone = structure:clone()
		structure_clone.Parent = game.Workspace
		structure_clone.Name = "Structure_"..player.Name
	end
end

function PlayerLeaving(plr)
	local key = "Structure_"..plr.Name
	StructureStore:SetAsync(key, game.Workspace["Structure_"..plr.Name])
end

game.Players.PlayerAdded:connect(PlayerEntered)
game.Players.PlayerRemoving:connect(PlayerLeaving)

1 answer

✓ Accepted answer

Considering what the output says, the problem comes from the fact your StructureStore value is empty, wich means that game:GetService("DataStoreService"):GetDataStore("StructureStore") returned nil. My deduction is that your script simply failed at creating a data store. Did you try to launch your script in online mode ? (Sometimes, data stores can't be created while in test mode)

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