Unable to assign property Value. string expected, got Instance (Unsolved)

Hey, So I am working on this game that utilizes a data store and a string value for loading in UI. Everything works fine, however, theres a problem. I have in place a textbutton that will fire a event with the name of the UI. However whenever the server tries to change the string values value to the name, it get’s the error as said in the topic name.
Here’s the local script:

local tb = script.Parent
local sound = script.Parent["Button Click Release"]

local name = script.Parent.Parent.Parent.Name
tb.MouseButton1Click:Connect(function()
	sound:Play()
	wait(1)
	sound:Stop()
	
	game:GetService('ReplicatedStorage'):WaitForChild('Events'):WaitForChild('UiOpen'):FireServer(name)
	script.Parent.Parent.Parent.Parent.ActualGame.Enabled = true
	script.Parent.Parent.Parent.Enabled = false
end)

And the server script:

local dataStore = game:GetService('DataStoreService'):GetDataStore('LastUi')

game:GetService('Players').PlayerAdded:Connect(function(plr)
	local value = Instance.new('StringValue')
	value.Name = 'LastUi'
	value.Parent = workspace
	

	local data

	local success, result = pcall(function()
		data = dataStore:GetAsync("Player_"..plr.UserId)
	end)
	
	if success then
		if data then
			value.Value = data
		else
			value.Value = 'LoadingPage'
		end
	end
	wait(1)
	local name = value.Value
	
	local ui = plr.PlayerGui:FindFirstChild(name)
	if ui then
	ui.Enabled = true
		print(ui)
	end
end)


game:GetService('ReplicatedStorage').Events.UiOpen.OnServerEvent:Connect(function(name)
	if name then
		
		workspace.LastUi.Value = name
	end
end)


game.Players.PlayerRemoving:Connect(function(player)	
	local success, result = pcall(function()
		dataStore:SetAsync("Player_"..player.UserId, workspace.LastUi.Value)
	end)




	if success then
		print(result)
	else
		warn(result)
	end
end)

game:BindToClose(function()
	for _, player in ipairs(game.Players:GetPlayers()) do
		local success, result = pcall(function()
			dataStore:SetAsync("Player_"..player.UserId, workspace.LastUi.Value)
		end)




		if success then
			print(result)
		else
			warn(result)
		end
	end
end)

any help would be appreciated.

Update, I tried looking through other users with the same error and i really haven’t outputted anything. I have no clue how to fix this.

whenever you fire server from client the first parameter of function is the player that fired

local Storage = game:GetService('ReplicatedStorage')
Storage.Events.UiOpen.OnServerEvent:Connect(function(Player, Name)
	if Name then
		workspace.LastUi.Value = Name
	end
end)
1 Like

ah, i always forget that lol. thanks, it works after all these hours lol.

1 Like