Problem with passing character to event

My problem is that for some reason the client-side script does not correctly receive the cloned player’s character.

In the first module client-side script I specify:

onSpawnPlayer.OnServerEvent:Connect(function(player,character,play)
	if play then
		onSpawnPlayer:FireClient(player,character,play)
		warn(character.Name)
		warn(character)
		warn(character.Parent)
	end
end)

The result is that instead of a character I get nil.

1 Like

Can you show what “character” variable you are actually passing?
Also what do the warn statements say?

There are no warnings other than my own in the debug messages.

Here is the part of the client script where I clone the player character and pass it as an argument to the module:

local newCharacter=character:Clone()
		newCharacter.Parent=workspace
		newCharacter.Name="cloneCharacter"..player.Name
animationSpawnModule.AnimationSpawn(newCharacter)

In the module I get this argument:

function animationSpawnModule.AnimationSpawn(character,color)
onSpawnPlayerClone:FireServer(character,true)

In the 3rd server script I initialize events and send them to the client, and it is in this script that I receive nil instead of character:

onSpawnPlayer.OnServerEvent:Connect(function(player,character,play)
	if play then
		onSpawnPlayer:FireClient(player,character,play)
		warn(character.Name)
		warn(character)
		warn(character.Parent)
	end
end)

You’re passing “newCharacter” from the remote event right? From what it seems right now you’re passing “character” which might be nil?

Yes, you understood correctly.

I pass a character which must not be nil.

Just a question,
on client, you’re not doing player, character, play right? FireClient doesn’t need the player argument

I didn’t do that on the client. Only in the server script.

Here is the part of the client script where I should get the character but I get nil:

onSpawnPlayer.OnClientEvent:Connect(function(cloneCharacter,play)
	if play then
		cutSceneStart(cloneCharacter)
		print("cloneCharacter is a valid object: "..cloneCharacter.Name)
	end
end)

Client? Are you passing the localplayer? I’ve never tried passing a localplayer value to the server before but it’s possible that the server cannot get localplayer character therefore resulting in nil

It also seems like the character clone is being created on the client too, so the server can’t access it because it’s not created on the server

Either try doing everything on the same script (which will make your thing client-sided) or fire a remote event to the server for the creation of the character clone.

I think you’re right, I completely forgot about it. Now I’ll try to correct it.

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