RemoteFunction Arguments Randomizing

Hello Developer!

I have recently got a problem where the RemoteFunction’s arguments are not ordered correctly. I am not sure why or how this is happening, Hopefully this can be solved.

Server Script

game.ReplicatedStorage.PlaceFunc.OnServerInvoke = function(Target, TargetSurface, selection, side)
	local AddedPart = Target:Clone()
	print(TargetSurface) -- Target (Wrong)
	print(Target) -- Player (Wrong)
	print(selection) -- Part (Correct)
	print(side) -- Side (Correct)
	print(AddedPart) -- nil (Wrong)
	
	AddedPart.Parent = workspace

	local blacklist = {
		game.Workspace.Baseplate
	}

	for i, v in pairs(blacklist) do
		if v == selection.Adornee then
			selection.Adornee = nil
		end
	end

	if selection.Adornee == Target then
		if side == "Top" then
			AddedPart.CFrame = Target.CFrame + Vector3.new(0, Target.Size.Y/2 + AddedPart.Size.Y/2, 0)
		elseif side == "Bottom" then
			AddedPart.CFrame = Target.CFrame + Vector3.new(0, -Target.Size.Y/2 - AddedPart.Size.Y/2, 0)
		end
	end
end

Client Side

game.ReplicatedStorage.PlaceFunc:InvokeServer(mouse.Target, mouse.TargetSurface, selection.Adornee, "Top")

Sorry If this is an easy problem!

RemoteFunction.OnServerInvoke returns the client who invoked the server as the first parameter, and then tuples that the client have sent through.

To address your issue:

game.ReplicatedStorage.PlaceFunc.OnServerInvoke = function(Player, Target, TargetSurface, selection, side)

This should fix your problem right away.

Hmmm shouldn’t this work?

game.ReplicatedStorage.PlaceFunc.OnServerInvoke = function(Player, Target, TargetSurface, selection, side)
	local AddedPart = Target:Clone()
	print(Player) -- Player
	print(Target) -- Player 
	print(TargetSurface) -- Part
	print(selection) -- Enum.NormalId.Top
	print(side) -- Part
	print(AddedPart) nil
	AddedPart.Parent = workspace

	local blacklist = {
		game.Workspace.Baseplate
	}

	for i, v in pairs(blacklist) do
		if v == selection.Adornee then
			selection.Adornee = nil
		end
	end

	if selection.Adornee == Target then
		if side == "Top" then
			AddedPart.CFrame = Target.CFrame + Vector3.new(0, Target.Size.Y/2 + AddedPart.Size.Y/2, 0)
		elseif side == "Bottom" then
			AddedPart.CFrame = Target.CFrame + Vector3.new(0, -Target.Size.Y/2 - AddedPart.Size.Y/2, 0)
		end
	end
end

Client

game.ReplicatedStorage.PlaceFunc:InvokeServer(game.Players.LocalPlayer, mouse.Target, mouse.TargetSurface, selection.Adornee, "Bottom")

Not sure why it is still not ordered right

You don’t need to manually send game.Players.LocalPlayer, because it is automatically sent by default.

It might be better (and cleaner) to send your parameters inside a dictionary. The function shouldn’t be changing the order of these parameters, unless there’s something wrong with your code somewhere else.

Thank you! it worked perfectly.

Yeah, I’ve been looking into it and it does seem cleaner to send it in a dictionary. Thank you!