Struggling sending client info to the server

Started creating a chest loot system, where loot is supposed to spawn nearby a chest once that chest is opened by a player. Unfortunately, when sending over the center of the chest from client to server, it’s not sending over.

Here is the relevant portion of the local script, located inside of StarterCharacterScripts.

		local Center = common_chest:WaitForChild("Center")
		local OpenSound = Center:WaitForChild("Open")
		local Taken = common_chest:WaitForChild("Open")
		if Player:DistanceFromCharacter(Center.Position) <= Distance and Taken.Value == false then
			Taken.Value = true
			local ChestAnimation = common_chest:WaitForChild("ChestHumanoid"):LoadAnimation(common_chest:WaitForChild("ChestAnimation"))
			ChestAnimation:Play()
			OpenSound:Play()
			wait(1)
			print(Center)
			ChestOpenedRemote:FireServer(Center, "Common")
			ChestAnimation.Stopped:Connect(function()
				game.Debris:AddItem(common_chest, 0.1)
			end)
		end
	end

Here is the server script responsible for spawning the randomized loot.

ChestOpenedRemote.OnServerEvent:Connect(function(player, chest_location, chest_type)
	if chest_type == "Common" then
		local Loot = ChestLootFolder:WaitForChild("Common"):GetChildren()
		local ran_amount = math.random(3)
		for i = 1,ran_amount do
			local RandomLoot = math.random(#Loot)
			local ChosenLoot = Loot[RandomLoot]:Clone()
			ChosenLoot.Parent = Workspace:WaitForChild("Obtainables")
			ChosenLoot.CFrame = chest_location.CFrame + Vector3.new(math.random(-4,4), math.random(4) ,math.random(-4,4))
			ChosenLoot.Anchored = false
		end
	end
end

Inside of the local script when printing Center, it prints the Center correctly.
However, inside of the server script when printing chest_location, of which is that same “Center” variable that was printed earlier on in the local script, it prints nil.

I am not entirely sure why Center is returning nil to the Server, even though Center is printing just fine from within the local script.

Any ideas?

Output

Are you creating the center on the client? If that is the case then the server cannot get a reference to the center since it was created locally.

1 Like

Adding on to that, if the center is created on the client, you could send the CFrame of the center through the argument and spawn the loot using that.

1 Like

I believe so. The Chests are randomly spawned from a local script in different locations that way chests are always in different locations for each player.

@Awesom3_Eric I’ll try sending the Center’s CFrame to the Server as opposed to the actual Center Instance.

Thank you, that resolved my issue. Don’t know why I didn’t try that in the debugging process!

1 Like