Hello, I have a problem with my script.
I don’t know why, but the player doesn’t want to rotate
I’ve already tried using CFrame.Angles, but nothing changes, the player doesn’t rotate.
local Hiding = false
local ExitPos = script.Parent.Parent:FindFirstChild("ExitPosition")
local HidingPos = script.Parent.Parent:FindFirstChild("HidePosition")
local sc = script.LockerClose
local so = script.LockerOpen
function Hide(Clicker)
if Hiding == false and Clicker.Character.Humanoid.Health >= 1 then
Hiding = true
so:Play()
workspace.CurrentCamera.CameraSubject = Clicker.Character.Head
Clicker.Character.HumanoidRootPart.CFrame = CFrame.new(Clicker.Character.HumanoidRootPart.Position, script.Parent.Parent.Door1.Position)
Clicker.Character.HumanoidRootPart.Anchored = true
local Hum = Clicker.Character.Humanoid:LoadAnimation(script.Parent.Parent.Open)
Clicker.Character.HumanoidRootPart.CFrame = ExitPos.CFrame
Hum:Play()
script.Parent.FrameAttachment2a.Orientation = Vector3.new(0,-90,0)
script.Parent.FrameAttachment2b.Orientation = Vector3.new(0,-90,0)
script.Parent.FrameAttachment1a.Orientation = Vector3.new(0,-90,0)
script.Parent.FrameAttachment1b.Orientation = Vector3.new(0,-90,0)
Hum.Stopped:Wait()
Clicker.Character.HumanoidRootPart.Anchored = false
Clicker.Character.HumanoidRootPart.CFrame = HidingPos.CFrame
sc:Play()
script.Parent.FrameAttachment2a.Orientation = Vector3.new(0, -180, 0)
script.Parent.FrameAttachment2b.Orientation = Vector3.new(0, -180, 0)
script.Parent.FrameAttachment1a.Orientation = Vector3.new(0, 0, 0)
script.Parent.FrameAttachment1b.Orientation = Vector3.new(0, 0, 0)
script.Parent.ProximityPrompt.TriggerEnded:Connect(Hide)
Otherwise, the rest of the script executes correctly.
You may even what to do a
local rs = game:GetService(“RunService”) … up top
Then use a: rs.Stepped:Wait() in place of the task.wait(0.33)
To get an actual frame update time.
Hello, The line of code that you’re using to rotate the character might not be having the effect you want because it is actually setting the position of the HumanoidRootPart to the position of ExitPos, and orienting it to face the Door1 object.
Here, the character’s HumanoidRootPart’s position is being set to its own position (which does nothing), and its look vector (the direction it’s facing) is being set towards Door1.
If you want to rotate the player to face the door, you should do the following:
local lookAtVector = script.Parent.Parent.Door1.Position - Clicker.Character.HumanoidRootPart.Position
Clicker.Character.HumanoidRootPart.CFrame = CFrame.new(Clicker.Character.HumanoidRootPart.Position, lookAtVector)
This will make the character’s HumanoidRootPart face towards the Door1.
You might also want to consider using the BodyGyro technique that I mentioned in my previous answer to controlling the rotation of the character, as it gives you more fine-grained control and can avoid some of the issues with directly setting the CFrame. Here is an example of how you could use it:
-- Create a BodyGyro if it doesn't exist yet
local gyro = Clicker.Character.HumanoidRootPart:FindFirstChild("BodyGyro")
if not gyro then
gyro = Instance.new("BodyGyro")
gyro.Name = "BodyGyro"
gyro.Parent = Clicker.Character.HumanoidRootPart
end
-- Now use the BodyGyro to rotate the character
gyro.CFrame = CFrame.new(Clicker.Character.HumanoidRootPart.Position, script.Parent.Parent.Door1.Position)
Also, remember to set the gyro.MaxTorque to a high value (such as Vector3.new(math.huge, math.huge, math.huge)) so it has enough power to rotate the player.