I'm losing data between the server-side script and the client-side script

Hello I’m working on a game where I manage houses spawned by users.
Each Neighborhood is a different place to set houses.
Each neighborhood can have between 4 and 9 houses.
Sometimes when some neighborhood are not full of users because they havent been claimed yet, there’s a model called Empty spawning to a future player can come and spawn a house to get it registered in the data store.

So in my server script I use a RemoteEvent to talk to my local script, and when I print both what they send, they don’t show the same result…

In server script :

local function sendHousesInfo(player, x, y)

	local houses = getNeighborhoodHouses(x, y)
	if houses then
		local houseCount = countHouses(houses)
		print("HouseManager - I'm sending", houseCount, " - the name of the house model", player.Name)

		for houseNumber, houseInfo in pairs(houses) do
			print("HouseManager - Sending house:", houseNumber, "Type:", houseInfo.houseType, "Owner:", houseInfo.ownerName)
		end

		UpdateNeighborhoodHouses:FireClient(player, {
			quarterPosition = {
				X = x,
				Y = y
			},
			houses = houses
		})
	end
end


Sorry for the french, yes I like printing in french.
Anyway as you can see, it shows what the server script is gonna send to the client. Houses have a number ID thanks to attributes.

Here the local script receiving :


ReplicatedStorage.UpdateNeighborhoodHouses.OnClientEvent:Connect(function(data)
	print("=== Datas received for the neighborhood ===")
	print("Neighborhood:", data.quarterPosition.X, data.quarterPosition.Y)

	-- Debug: let's see the houses we just received now.
	for houseNumber, houseInfo in pairs(data.houses) do
		print("House received:", houseNumber, "Type:", houseInfo.houseType, "Owner:", houseInfo.ownerName)
	end

	local neighborhood = waitForNeighborhood(
		data.quarterPosition.X,
		data.quarterPosition.Y
	)

So we received in total 2 houses (Rip the 7 one)

And the local script will start working with the “Zwei” one.

Later in the prints, it’ll talk about :


But after that, it does other thing and never mentions the 7th House.

UNTIL A WEIRD THING HAPPENS :

I dont have screenshots for now, but believe me, adding the 5th house helped the 7th to be received in local script. 5th appeared too since I made it in the data store.
But without the 5th, the 7th doesn’t come.
If I add the 6th, the 7th doesn’t come too.
So it’s very very weird.

What happens inside getNeighborhoodHouses? I would suspect that if they are instances, perhaps those instances do not exist on the server or the client.

And remember not to use UnreliableRemoteEvent for this :wink:

Wow, devforum notifications are fast, 6 hours for it to appear in my notifications :skull:

1 Like

So this is a remoteevent, what do you mean by UnreliableRemoteEvent ?

local function getNeighborhoodHouses(x, y)
	print("HouseManager - Let's have a look for existing houses", x, y)

	-- Récupération directe des données sans pcall
	local neighborhoodData = neighborhoodDataStore:GetAsync("Neighborhood_" .. x .. "_" .. y)

	if neighborhoodData then
		print("Données brutes du quartier:", neighborhoodData)

		local houses = {}
		for houseNumber = 1, 9 do
			local houseKey = "HouseNumber" .. houseNumber
			local houseData = neighborhoodData[houseKey]

			if houseData then
				print("House found:", houseKey, "Type:", houseData.houseType)
				-- Récupérer le nom du joueur associé à l'ID propriétaire
				local username = Players:GetNameFromUserIdAsync(houseData.owner)

				houses[houseNumber] = {
					owner = houseData.owner,
					ownerName = username,
					houseType = houseData.houseType,
					claimDate = houseData.claimDate,
					Texte = houseData.Texte or "Write something here"
				}
			else 
				warn("There's no house in the Neighborhood ID", houseKey)
			end 
		end

		return houses
	else
		print("No data found for this neighborhood", x, y)
	end

	return nil
end