Object turns into player when passed through remote event

Hello! I tried to make a script that automatically sets the Position of a part to be the position of the players humanoid root part. I used a localscript to get local player and the players humanoid root part and I passed it through a remote event.

However whenever I pass it, it thinks that the humanoid rootPart is a Player, and not an actual child of the players character. I’ve tried other things but to no avail.

This is the local script im using:

local remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")
local plr = game.Players.LocalPlayer
local char = plr.Character
local root = char:FindFirstChild("HumanoidRootPart")
remote:FireServer(plr, root)

As for the Script I’m using for it to Recieve the remote event, this is it:

local function p(plr, root)
    while true do
        game.Workspace.Part.Position = root.Position
        task.wait(0.03)
    end
end
 
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(p)
1 Like

The player who fires the remote is automatically set to be the first parameter, so what you are receiving on the server is effectively: player, player, root. You don’t need to send the player yourself.

3 Likes

Oh… That’s interesting, but how does that explain why whenever I specify HumanoidRootPart, it turns into a player?

1 Like

Never mind, I understand. Turns out whenever you make a client to server remotevent it automatically will create that parameter and I was creating a second and third paramter. But I’m still confused as to why that changed the HumanoidRootPart

1 Like

It changed the HumanoidRootPart because you had 2 parameters on the server script yet sent 3 from the client (due to the player automatically being sent). This means that the second parameter in the server will be whatever the second parameter was from the client which is the player (even though it looks like the first one). The HumanoidRootPart is sent to the server but there isn’t a parameter to pick it up, it won’t cause an error but you just won’t be able to use it.
Parameters can be named different names which may be why your confused on why it changed the humanoid root part. Here’s an example for you:
Client / Local Script:

local banana = 10
game.ReplicatedStorage.Event:FireServer(banana)

Server / Normal Script:

game.ReplicatedStorage.Event.OnServerEvent:Connect(function(player, apple)
print(player)
print(apple)
end)

The player parameter on the server would be equal to the player that fired the event and the apple parameter would be equal to whatever banana is. Even though apple and banana are two completely different names they are the same value due to where they were placed in the parameters.

I hope this clears things up for you good luck with your journey from here.

1 Like

Dude thank you so much! I got it working and you explained it very well. Appreciate it a lot

2 Likes

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