Error when i try to save a string to a datastore. (Datastore2)

local played = game.Players.LocalPlayer:WaitForChild("played").Value
local starter_bunker_message = script.Parent.Parent.Parent.starter_bunker_message
local button = script.Parent
local menu = button.Parent
local Blur = game.Lighting.Blur
local maps = workspace.maps
local ReplicatedStorage = game.ReplicatedStorage
local mapstorage = ReplicatedStorage.local_map_storage
local bunker_name = game.Players.LocalPlayer.Name
local functions = require(game.Players.LocalPlayer.PlayerScripts.local_functions);

button.MouseButton1Click:Connect(function(clicked)
	if played then
	print ("Played before.")
	else
		print(starter_bunker_message.on.Value)
		menu:WaitForChild("close_menu").Value = true
		wait (1)
		starter_bunker_message.on.Value = true
		local result = ReplicatedStorage.starter_bunker:InvokeServer()
		wait(2)
		starter_bunker_message.off.Value = true
		repeat
			
		until result == true
		print (bunker_name)
		ReplicatedStorage.save_map:FireServer(bunker_name)
end
end)

22:15:44.518 - error when player left! Invalid at input.bunker_name because: Invalid type (Instance)

I think this error is trying to say that im saving the instance of my name rather than the string.

Tried assigning the instance to a variable and then saving it but it doesnt work

It shouldn’t because you can only save strings to the database Roblox’s DataStoreService interfaces with.
The title doesn’t match the contents of your post, are you saving a string or an instance?

+This isn’t all the code that’s involved, what’s the event listener??

bruh, you didn’t even get the datastore

this is pretty obviously a local script if you were paying attention, which you are clearly not

Its a serverscript, a called save_script but i dont want to leak my code.

How do you expect us to help you then?

We need something to spot errors in, otherwise if you think an issue can be solved by simple debugging I recommend doing that beforehand.

This is the :Set() function on the serverside.

bunkernameStore:Set(new_name)

I made a function that uses new_name as a parameter, and my event listener uses the parameter sent by the remote event in the function.

Also heres my entire script now that i think about it, datastore2 will be the only thing ill have major trouble with, i should be fine for the rest, and i wont need to supply anymore scripts as ill be fine making the game by myself.

DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
ServerStorage = game:GetService("ServerStorage")
Players = game:GetService("Players")
ReplicatedStorage = game.ReplicatedStorage
objectstore = ReplicatedStorage.bunker_obj_storage

default_omega_coins, default_likes, default_wins = 0, 0, 0


default_bunker_terrain_position = {
	Vector3.new(26.927,-33.383,-540.507)
}



default_bunker_terrain_size = {
Vector3.new(1,1,1)
}

default_bunker_terrain_rotation = {Vector3.new(0,0,0)
	
}

default_bunker_materials = {
	"Mud",
}

DataStore2.Combine(
 "Test30", "Played", "Wins", "Ωmega Coins", "Likes", "bunker_name", "object_name",
 "object_position", "object_rotation", "terrain_position", "terrain_rotation", "terrain_size", "terrain_materials"
)

Players.PlayerAdded:Connect(function(Player)
	winsStore = DataStore2("Wins", Player)
	coinStore = DataStore2("Ωmega Coins", Player)
	likesStore = DataStore2("Likes", Player)
	
	
	bunkernameStore = DataStore2("bunker_name", Player)
	
	
	objectnameStore = DataStore2("object_name", Player)
	
	objectpositionStore = DataStore2("object_position", Player)

	objectrotationStore = DataStore2("object_rotation", Player)

	terrainpositionStore = DataStore2("terrain_position", Player)
	
	terrainrotationStore = DataStore2("terrain_rotation", Player)

	terrainsizeStore = DataStore2("terrain_size", Player)
	
	-- :Get()Variables
	objectpositionGet = DataStore2("object_position", Player):Get({})

	objectrotationGet = DataStore2("object_rotation", Player):Get({})

	terrainpositionGet = DataStore2("terrain_position", Player):Get(default_bunker_terrain_position)

	terrainrotationGet = DataStore2("terrain_rotation", Player):Get(default_bunker_terrain_rotation)

	terrainsizeGet = DataStore2("terrain_size", Player):Get(default_bunker_terrain_size)

	terrainmaterialsStore = DataStore2("terrain_materials", Player)
	terrainmaterialsGet = DataStore2("terrain_materials", Player):Get(default_bunker_materials)
	
	local played = Instance.new("BoolValue", Player)
	played.Name = "played"
	if terrainmaterialsStore[1] then
		played = true
	end
	
	local leaderstats = Instance.new("Folder") do
		leaderstats.Name = "leaderstats"
	end
	local wins = Instance.new("IntValue") do
		wins.Name = "Wins"
		wins.Parent = leaderstats
	end
	local omega_coins = Instance.new("IntValue") do
		omega_coins.Name = "O$"
		omega_coins.Parent = leaderstats
	end
	local likes = Instance.new("IntValue") do
		likes.Name = "Likes"
		likes.Parent = leaderstats
	end
	leaderstats.Parent = Player
	
function save_to_model(player, bunkernameStore) ---------------------------------------------------- function start
	local newMap = ServerStorage.empty_map:Clone() do
		newMap.Name = Player.Name
		local name = Instance.new("StringValue", newMap.params)
		if bunkernameStore then
			name.Value = bunkernameStore
			else
			name.Value = "Bunker Construction Site"
		end
		local offset = Instance.new("NumberValue", newMap.params)
		--offset.Value = Player:WaitForChild("designated_bunker_position")
	end
		local terrain = newMap.terrain:WaitForChild("cubes")
		print (terrainmaterialsStore)
		print (terrainmaterialsGet)
	for i, v in pairs(terrainmaterialsGet) do
		print (i) print(v)
		local Part = Instance.new("Part") do
				
			Part.Name = v
				
			Part.CFrame = CFrame.new(terrainpositionGet[i])
			Part.Size = Vector3.new(terrainsizeGet[i])
			Part.Orientation = Vector3.new(terrainrotationGet[i])

			Part.Parent = terrain
			Part.Anchored = true
			Part.Transparency = 1
			Part.CanCollide = false
			newMap.Parent = game.Workspace.maps
			end
			
			for i, v in pairs (objectnameStore:Get({})) do
					
				local obj = objectstore[v]:Clone()
				
			obj.Position = CFrame.new(objectpositionGet[i])
				
	obj.Orientation = Vector3.new(objectrotationGet[i])
			end
			end
				
		end  --------------------------------------------------------------------------------------------- function end
		
		
		
		
		
		
	
		function model_to_save(new_name) ---------------------------------------------------------function start
			local terrain = workspace.maps[Player.Name].terrain:WaitForChild("cubes"):GetChildren()
			local mapobj = workspace.maps[Player.Name].obj:GetChildren()

			bunkernameStore:Set(new_name)
			
			    terrainposition,
				terrainrotation,
				terrainsize,
			    terrainmaterials,
			    objectposition,
			    objectrotation = {},{},{},{},{},{}
			
for i = 1, #terrain do
		local child = terrain[i]
				
		if child:IsA("Part") then
			
			terrainposition[i] = Vector3.new(child.Position.X,child.Position.Y,child.Position.Z)
			terrainrotation[i] = Vector3.new(child.Rotation.X,child.Rotation.Y,child.Rotation.Z)
			terrainsize[i] = Vector3.new(child.Size.X,child.Size.Y,child.Size.Z)
			terrainmaterials[i] = child.name
			end
			end
			
			for i = 1, #mapobj do
				local objchild = mapobj[i]
				if objchild:IsA("Model") then
					local partchild = #mapobj[i]
					for i = 1, #partchild do
						if partchild:IsA("Part", "MeshPart") then
							objectposition = Vector3.new(partchild[i].Position.X,partchild[i].Position.Y,partchild[i].Position.Z)
							objectrotation = Vector3.new(partchild[i].Orientation.X,partchild[i].Orientation.Y,partchild[i].Orientation.Z)
							
						end
					end
				end
			end
			terrainpositionStore:Set(terrainposition)
			
			terrainrotationStore:Set(terrainrotation)
			
	
			terrainsizeStore:Set(terrainsize)
			terrainmaterialsStore:Set(terrainmaterials)
			objectpositionStore:Set(objectposition)
			objectrotationStore:Set(objectrotation)	
                                                 
		end -------------------------------------------------------------------------------------------function end


	ReplicatedStorage:WaitForChild("load_map").OnServerEvent:Connect(function(player)
	save_to_model(player)
end)

ReplicatedStorage:WaitForChild("save_map").OnServerEvent:Connect(function(name)
	model_to_save(name)
end)
end)

It seems as though you’re just passing the local player’s name and essentially just saving that to the store - are you doing that intentionally or did you mean to reference some object’s name instead?

I didn’t really read through the entire code since I don’t have time.

Its just supposed to be a name for the bunker, in this code its supposed to supply a default bunker that names it the same name as the player. I tried using a regular string and the error still happens.

OK update: it seems to work if i put a string in the :Set() function directly in the serverscript.