Local Server Image Loading Fix

This plugin will fix the problem where Game images won’t load in local test servers.


This issue has been referenced at least three times in the past few days:


How it works

Problem:

  • Game assets won’t load because the GameId is 0
  • The GameId is only 0 for the clients, not the server.
  • The GameId isn’t replicating to test clients for some reason

Solution:

  • Manually replicate the GameId with a Value object
  • Set the GameId by script.

Source
while not game:FindService("NetworkServer") and not game:FindService("NetworkClient") do
	game.ChildAdded:wait()
end
local placeDataValue
if game:FindService("NetworkServer") then
	placeDataValue = game:GetService("ReplicatedFirst"):FindFirstChild("PlaceData")
	
	if placeDataValue then
		placeDataValue:Destroy()
	end
	placeDataValue = Instance.new("StringValue")
	placeDataValue.Name = "PlaceData"
	placeDataValue.Value = game:GetService("HttpService"):JSONEncode({
		UniverseId = game.GameId,
		PlaceId = game.PlaceId
	})
	placeDataValue.Parent = game:GetService("ReplicatedFirst")
elseif game:FindService("NetworkClient") then
	placeDataValue = game:GetService("ReplicatedFirst"):WaitForChild("PlaceData", math.huge)
	local placeData = game:GetService("HttpService"):JSONDecode(placeDataValue.Value)
	game:SetUniverseId(placeData.UniverseId)
	game:SetPlaceId(placeData.PlaceId)
end

4 Likes