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

When Teleporting Two Players, Why Does This Script Not Make Them Stand Still and Face Each Other?

Asked by
8391ice 91
7 years ago

My game involves periodical battles. At the start of each one, two players are teleported to a ring a few dozen studs apart, and they are supposed to face one another and not be able to move for the first couple of seconds, then after a series of GUIs, be able to fight. I've tried anchoring the HumanoidRootPart, but it did something strange; it's a bit hard to explain, but the player was able to move around independent of its body, almost as if the player's "soul" had escaped from its body. The same thing occurred when I attempted to rotate the HumanoidRootPart in order to get the players to face each other.

This is quite bizarre to me. If I don't script anything about the HumanoidRootPart, they teleport just fine and are standing perfectly. They just aren't facing one another and are still able to walk around freely. How can I accomplish getting them to face each other and stand still while still preserving the idle animations that they make? (I'm using R15 for my game, by the way.)

This is my script.

function teleportToBattle(p1, p2)
    player1 = game.Players:FindFirstChild(p1.Name) --Finding the players.
    player2 = game.Players:FindFirstChild(p2.Name)
    if player1 and player2 then --If they are both present.
        player1.Character.HumanoidRootPart.Anchored = true --To keep the player still.
        player1.Character.UpperTorso.CFrame = CFrame.new(Vector3.new(-62, 8, -89.5)) --Teleports tthem to their respective position.
        player1.Character.HumanoidRootPart.Rotation = Vector3.new(0, -90, 0) --To make them face one another.
        player2.Character.HumanoidRootPart.Anchored = true
        player2.Character.UpperTorso.CFrame = CFrame.new(Vector3.new(-48, 8, -89.5))
        player2.Character.HumanoidRootPart.Rotation = Vector3.new(0, 90, 0)
    elseif player1 and not player2 then --In case one leaves or lags out.
        print("player1 wins")
    elseif player2 and not player1 then
        print("player2 wins")
    else
        print("no one wins")
    end
end
0
Use UpperTorso instead of HumanoidRootPart TheUniPiggy 77 — 7y
0
That killed the players. 8391ice 91 — 7y
0
PrimaryPart? TheUniPiggy 77 — 7y
0
I just tried that, and when the players teleported, they were laying down and getting stuck in the floor instead of standing up. 8391ice 91 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Lol. I love your description. I'm guessing you could have a part in the middle and do . This will make the player face the part.

player1.Character.Torso.CFrame = CFrame.new(player1.Character.Torso.CFrame.p,Vector3.new(CenterPart.CFrame.p.X,player1.Character.Torso.CFrame.p.Y,CenterPart.CFrame.p.Z))

This should work.

0
Oh my goodness, it did work! I never would have thought of using a part to have the players face it! Thank you very much! 8391ice 91 — 7y
0
And I stopped them from moving by just setting their walkspeed to 0. Worked perfectly! 8391ice 91 — 7y
0
Lol. No problem though anchoring the torso could've worked too. Meltdown81 309 — 7y
Ad

Answer this question