I have a script that moves parts of a model when a key is held.
I want the parts (connected to the black objects behind them) to move according to the direction that the black objects are facing.
(The top one does this fine, but the bottom one doesn’t)
In my script, it only goes by the y-axis, and changing the pivot orientation in any way makes it glitch out.
--server (ServerScriptService)--
local REP = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
local remote = REP.FK1
local Digit1 = game.Workspace.RobotArm.Claw.DigitsKnuckles.Digit1
local Digit2 = game.Workspace.RobotArm.Claw.DigitsKnuckles.Digit2
local Digits
local speed = -2
RS.Heartbeat:Connect(function()
if Digits then
local x,y,z = Digit1.CFrame:ToOrientation()
Digit1:PivotTo(CFrame.Angles(math.clamp(x - math.rad(speed), 0, math.rad(90)), y, z) + Digit1:GetPivot().Position)
end
end)
RS.Heartbeat:Connect(function()
if Digits then
local x,y,z = Digit2.CFrame:ToOrientation()
Digit2:PivotTo(CFrame.Angles(x, math.clamp(y - math.rad(speed), 0, math.rad(90)), z) + Digit2:GetPivot().Position)
end
end)
remote.OnServerEvent:Connect(function(plr, state)
Digits = state
end)
Is there any way to make it so that it can go based on the orientation and not setting angles? (while also having math.clamp to stop it from going past 90 degrees)