I’m trying to make a placement system with rotation feature, when I rotate to Y axis at first it works normally, but when I rotate the item on Z axis once (90 degrees) and rotate Y axis again, it rotates Y in global Axis, I want it to rotate on local Y axis
(Y Axis rotation is showed as the fast rotating ones, I apologize for not having a text on screen to indicate which rotation is Y)
this is the script in charge for the cframe (module script)
self.RunService = RS.Heartbeat:Connect(function()
local LPlr = game:GetService("Players").LocalPlayer
local Mouse = LPlr:GetMouse()
Mouse.TargetFilter = workspace.Placing
local MousePosition = Mouse.Hit.Position
local PlacingPosition = Vector3.new(Round(MousePosition.X, self.Grid), Round(MousePosition.Y, self.Grid), Round(MousePosition.Z, self.Grid))
local PlacingCFrame = (CFrame.new(PlacingPosition) * CFrame.new(self.CFrameOffset)) * CFrame.fromEulerAngles(Rad(self.Rotation))
self.PrototypePosition = PlacingPosition
self.Prototype.PrimaryPart.CFrame = (PlacingCFrame)
end)
and this one is the local script
local ObjectProfile = nil
local ObjectRotationX = 0
local ObjectRotationY = 0
local ObjectRotationZ = 0
local TweenRotationX = Instance.new("NumberValue")
local TweenRotationY = Instance.new("NumberValue")
local TweenRotationZ = Instance.new("NumberValue")
UIS.InputBegan:Connect(function(Input, GameProcess)
if GameProcess then return end
if Input.KeyCode == Enum.KeyCode.E then
if ObjectProfile == nil then
ObjectProfile = GridPlacingModule.New({DataName = "Banana", ModelName = "Banana", DisplayName = "Banana", CFrameOffset = Vector3.new(0, 4.25, 0)})
ObjectRotationX = ObjectProfile.Rotation.Y
ObjectRotationY = ObjectProfile.Rotation.Y
ObjectRotationZ = ObjectProfile.Rotation.Z
TweenRotationX.Value = ObjectProfile.Rotation.Y
TweenRotationY.Value = ObjectProfile.Rotation.Y
TweenRotationZ.Value = ObjectProfile.Rotation.Z
else
ObjectProfile:Stop()
ObjectProfile = nil
end
elseif Input.KeyCode == Enum.KeyCode.R then
if ObjectProfile ~= nil then
ObjectRotationY += 90
TS:Create(TweenRotationY, TweenInfo.new(0.2, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Value = ObjectRotationY}):Play()
end
elseif Input.KeyCode == Enum.KeyCode.T then
if ObjectProfile ~= nil then
if ObjectRotationY / 180 == math.round(ObjectRotationY / 180) then
ObjectRotationX += 90
TS:Create(TweenRotationX, TweenInfo.new(0.2, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Value = ObjectRotationX}):Play()
else
ObjectRotationZ += 90
TS:Create(TweenRotationZ, TweenInfo.new(0.2, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Value = ObjectRotationZ}):Play()
end
end
end
end)
TweenRotationX:GetPropertyChangedSignal("Value"):Connect(function()
if ObjectProfile ~= nil then
local Val = TweenRotationX.Value
print("X - "..tostring(Val))
ObjectProfile.Rotation = Vector3.new(Val, ObjectProfile.Rotation.Y, ObjectProfile.Rotation.Z)
end
end)
TweenRotationY:GetPropertyChangedSignal("Value"):Connect(function()
if ObjectProfile ~= nil then
local Val = TweenRotationY.Value
print("Y - "..tostring(Val))
ObjectProfile.Rotation = Vector3.new(ObjectProfile.Rotation.X, Val, ObjectProfile.Rotation.Z)
end
end)
TweenRotationZ:GetPropertyChangedSignal("Value"):Connect(function()
if ObjectProfile ~= nil then
local Val = TweenRotationZ.Value
print("Z - "..tostring(Val))
ObjectProfile.Rotation = Vector3.new(ObjectProfile.Rotation.X, ObjectProfile.Rotation.Y, Val)
end
end)