Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Other player's characters don't teleport with their Humanoid Root Part from local script?

Asked by 4 years ago
Edited 4 years ago

I'm using a local script to move both the local player's character and other players' characters. To do this, I'm changing the position of their humanoid root part. For some reason, this only works with the local player's character, while other player's humanoid root parts are teleported but the characters are left behind.

char.HumanoidRootPart.Position = tileGrid:FindFirstChild("PlayerStart"..playerInt.Value).Position + Vector3.new(0,8,0)

This is the bit that moves the local player's root part.

for i,v in pairs(Players:GetChildren()) do  --creates a clientside model of other players already in the game
    if v:WaitForChild("PlayerInteger").Value ~= playerInt.Value then
        print()
        if otherPlayer1 == nil then
            game.workspace:WaitForChild(v.Name).HumanoidRootPart.Position = tileGrid:FindFirstChild("PlayerStart"..otherPlayerInt1.Value).Position + Vector3.new(0,8,0)
        end
    end
end

And this is the bit that teleports the root part of the other player. Note that the root part is teleported fine, only the character is left behind. Also, whenever I animate the other character's root part (the animation is a simple arc to make the character look like they are jumping) later in the script, the character moves up and down with the root part, although it is in the wrong position because it didn't teleport initially.

I'm wondering if this is just a bug of trying to use local scripts to manipulate other players' characters other than the local player, and if there are any workarounds to this. Or maybe something is wrong with my code. Hope somebody has an idea

EDIT: I cut the question down to just the bare essentials of what I'm asking

0
You can only teleport your own character using a local script. If you want to teleport other player's characters from a local script, then you'd have to use a remote event to tell the server. AbusedCocopuff4 105 — 4y
0
Also, you teleport characters using :Move(position). You can also do Character:SetPrimaryPartCFrame(part.CFrame) as well. AbusedCocopuff4 105 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

A local script is unable to teleport every player. Here's why.

A client has full control over its character and that control can only be overridden by the server. A local script enables to client to:

  • Change their WalkSpeed.
  • Change their HipHeight.
  • Change their JumpPower.
  • Change their own Position or CFrame.
  • Play an animation that can be seen by the server (only in some cases)

If you want to teleport every player and not just one player, leave that to the server. A client cannot teleport every player because of FE, but it can teleport its own character to wherever it pleases.

If you are going to use SetPrimaryPartCFrame() instead of Move() (although both work), first check to make sure that the PrimaryPart isn't assigned to nil:

if Character.PrimaryPart then

If the condition passes, that means that there is a part assigned to PrimaryPart. You can then proceed to use the method:

Character:SetPrimaryPartCFrame(CFrame.new(0,0,0)) -- Insert a CFrame here

If you do decide to use the method, take note of the following things:

  • The HumanoidRootPart will inherit the target's CFrame and will force the Character to have a similar CFrame.
  • Because CFrame is both Position and Orientation, the HumanoidRootPart may rotate when it is moved to its given CFrame.
Ad

Answer this question