Value in Server is "MagicEight", but in Client its nil

I am trying to determine which ball is owned, but the name of the ball is nil in Client:
This is the Server Script:

local DataStoreService = game:GetService("DataStoreService")
local MagicEight = DataStoreService:GetDataStore("MagicEight")
-- Load
game:GetService("Players").PlayerAdded:Connect(function(player)
	local userId = player.UserId


	-- Read data store key
	local getSuccess, currentData, chyba = pcall(function()
		return MagicEight:GetAsync(userId)
	end)

	local MagicEight = currentData
	local BallNameDebugger = Instance.new("StringValue")
	BallNameDebugger.Parent = script
	BallNameDebugger.Value = "MagicEight"
	local BallName = BallNameDebugger.Value

	if getSuccess then
		game.Workspace.ClientValuesToServer.BallOwnership:FireClient(player, MagicEight, BallName)
		print(MagicEight)
		print(BallName)
	else
		-- Handle error if data retrieval fails
		warn("Failed to retrieve data for player " .. player.Name..". Reason: "..chyba)
	end
end)

And this is the Client Script:

game.Workspace.ClientValuesToServer.BallOwnership.OnClientEvent:Connect(function(player, MagicEight, BallName)
	wait(1)
	if BallName == script.Parent.Parent.Parent.ViewportFrame.WorldModel:FindFirstChildWhichIsA("Part").Name then
		script.Parent.Value = MagicEight 
	elseif BallName == nil then
		script.Parent.Value = MagicEight
		print(nil)
	end
end)

In the client script, remove player from OnClientEvent

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.