Issue with RemoteEvents

Hi, small issue trying to pass CFrames through remote events.

Client-side
local function OnPromptTriggered(IsPropHeld)
	while IsPropHeld do
		task.wait(0.05)
		GivePropPositionCFrame:FireServer(PropPosition.CFrame)
	end
end
PromptTriggered.OnClientEvent:Connect(OnPromptTriggered)
Server-side
GivePropPositionCFrame.OnServerEvent:Connect(function(RequiredPropCFrame)
	if IsPropHeld == true then
		for i = 0, 1, 0.001 do 
			wait()
			Prop.CFrame = Prop.CFrame:Lerp(RequiredPropCFrame, i) 
		end	
	end
end)

The error it gives is “Unable to cast Instance to CoordinateFrame”. As far as I can tell, what is being passed is a CFrame and therefore it should not have an issue.

Any help is appreciated
Thanks

Simple mistake, happened often to me too. The event on the server .OnServerEvent has a default player argument thats always the first one, to fix your code just add like (plr,cframe) and you should be good

1 Like

Try this :

Client
local function OnPromptTriggered(IsPropHeld)
	while IsPropHeld do
		task.wait(0.05)
		GivePropPositionCFrame:FireServer(PropPosition.CFrame)
	end
end
PromptTriggered.OnClientEvent:Connect(OnPromptTriggered)
Server
GivePropPositionCFrame.OnServerEvent:Connect(function(Player,RequiredPropCFrame)
	if IsPropHeld == true then
		for i = 0, 1, 0.001 do 
			task.wait()
			Prop.CFrame = Prop.CFrame:Lerp(RequiredPropCFrame, i) 
		end	
	end
end)

When using FireServer(), the first argument is the Player, on the client it’s automatically there. However, on the server it always has to be the first argument.

1 Like

Oh right, didn’t realise. It makes perfect sense but it’s never registered.
Also sorry for not using correct formatting for code, I just forgot to add the backticks. I’ve fixed it now.

Thanks for your help (and @Valkyrop too), that’s worked. I’ll try and remember that in the future!

2 Likes