Client to Server to Client Remote Event ends up nil

Heyo. Thru a single remote event having gone from one localscript, to serverscript, to another localscript, I am unable to pass thru a player object or at some object. You interact with the other player and I raycast to get their character and a loop to get their player instance then pass it thru the event. Apparently it dies out when it hits the other client and I have no idea why. Any response would be dope!

LocalScript 1

--targetplayer is raycastresult.Parent
local servertarget
	
	for _, v in pairs(Players:GetPlayers()) do
		if v.Name == tostring(targetplayer) then
			servertarget = v
			print(tostring(servertarget))
		end
	end
	if not servertarget then
		warn("Your loop didnt work numbnuts!")
	end

--...
--throw is remote event located in replicatedstorage
throw:FireServer(servertarget)

Server Script

throw.OnServerEvent:Connect(function(player,t)
	throw:FireClient(t)
end)

LocalScript2

throw.OnClientEvent:Connect(function(player)

	local HRP = player.Character:FindFirstChild("HumanoidRootPart")	--Nils out right here

end)
1 Like

You’re not passing any args in FireClient, the 1st parameter is the player you fire the client event to.

If you want everyone to get the target from the server, then you can do throw:FireAllClients(t), or if you only want the selected target to get the client call then you can just do throw:FireClient(t) and then in the client event handler you just assume that the “player” is the LocalPlayer, e.g.:

throw.OnClientEvent:Connect(function()
    local HRP = LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
end)

Assuming that the player is the LocalPlayer would be the same as doing throw:FireClient(t, t) with

throw.OnClientEvent:Connect(function(player)
    local HRP = player.Character:FindFirstChild("HumanoidRootPart")
end)

but that’s kinda redundant

2 Likes