Detecting the model that fired a RemoteEvent on the client

I’m making a code door system that pops up a GUI once you click on a keypad. Once you hit enter, the door you interacted with opens if you get the right code.

I send the model through a RemoteEvent in order to identify the door that the player interacted with. However, when the model reaches the clientside script, the “model” argument is nil. Obviously, I don’t want it to be nil.

--server script
script.Parent.Click.ClickDetector.MouseClick:Connect(function(player)
	if not debounce then
		debounce = true
		print(model)
		game.ReplicatedStorage.Code:FireClient(player, model)
	end
end)
--local script
game.ReplicatedStorage.Code.OnClientEvent:Connect(function(player, model)
	print(model) --returns nil
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(0.25), {CFrame = CFrame.new(model.Cam.Position)}) --problematic line, returns nil
	script.Parent.Parent.Enabled = true
	cmodel = model
end)

Is there any way to solve this issue? Alternatively, is there a better way for me to identify the model that fired the event?

Thanks in advance

1 Like

You don’t need the player parameter in the local script.

--local script
game.ReplicatedStorage.Code.OnClientEvent:Connect(function(model)
	print(model) --returns nil
	workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	game:GetService("TweenService"):Create(workspace.CurrentCamera, TweenInfo.new(0.25), {CFrame = CFrame.new(model.Cam.Position)}) --problematic line, returns nil
	script.Parent.Parent.Enabled = true
	cmodel = model
end)

Player is passed as an argument, but the client doesn’t need it because it’s given through LocalPlayer. Keep it in the serverscript, but remove it in the localscript

I keep forgetting about that. Thanks!

2 Likes