Im trying to force one player to go left. I tried using CFrame, but that makes the player go left in the games perspective. I want the player to go left through his. Is there a way to do this? Here is my script:
game.ReplicatedStorage.Roll.OnServerEvent:Connect(function(plr, char) local uppertorso = char.UpperTorso char.CFrame = char.CFrame - Vector3.new(10,0,0) end)
Hey Captain,
local players = game:GetService("Players") local player = players.LocalPlayer local uis = game:GetService("UserInputService") uis.InputBegan:Connect(function(obj, gp) if obj.KeyCode == Enum.KeyCode.Z and not gp then local char = player.Character or player.CharacterAdded:Wait() -- Gets the character of the player. local torso = char:FindFirstChild("HumanoidRootPart") -- The humanoid root part of the cahracter local pos = (torso.CFrame:pointToWorldSpace(Vector3.new(-5, 0, 0))) -- A position from the world space, 5 studs to the left of the humanoid root part. ------------- METHOD ONE ------------- local bp = Instance.new("BodyPosition") -- Make a Body Position to move the player. bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge) -- Set the max force to infinity bp.Position = pos -- Set the position of the body position to move towards. bp.Parent = torso -- Set the parent so that it moves the parent. repeat -- Meant to wait until the character reaches the position, so we can destroy it afterwards. wait() until ((torso.Position - pos).magnitude) < 1 bp:Destroy() -- Destroys the body position so that the player can move. ------------- --- ------------- ------------- METHOD TWO ------------- local hum = char:WaitForChild("Humanoid") -- Identifies the humanoid of the player. hum.WalkToPoint = pos -- Changes the walking point of the humanoid to walk towards that position. ------------- --- ------------- end end)
Thanks,
Best regards,
KingLoneCat
just use CFrame.RightVector
and multiply it by a negative number, since it'll be the opposite of RightVector, as theres no LeftVector
. also why are use creating a variable thats defined as the player's UpperTorso, and not using it.
game.ReplicatedStorage.Roll.OnServerEvent:Connect(function(plr, char) local uppertorso = char.UpperTorso uppertorso.CFrame = uppertorso.CFrame + uppertorso.CFrame.RightVector * -10 end)
also you cant send instances through arguments in OnServerEvent, so just set the cframe on the client, because it would replicate. or if you wanted it to move to the left instead of teleporting use MoveTo()
.
character.Humanoid:MoveTo(character.HumanoidRootPart.CFrame.Position + character.HumanoidRootPart.CFrame.RightVector * -10)