You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want it so whenever i tap on the key “R” it rotates, it works but it doesn’t always does.
What is the issue? Include screenshots / videos if possible!
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Alot but none was by my topic
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Here is the code i have.
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R and script.Parent.Visible == true then
if axis2 == false and selected ~= nil then
axis2 = true
if selected.Orientation == Vector3.new(0,0,0) then
game.ReplicatedStorage.Events.Rotation:FireServer(selected, 90)
elseif selected.Orientation == Vector3.new(0,90,0) then
game.ReplicatedStorage.Events.Rotation:FireServer(selected, 180)
elseif selected.Orientation == Vector3.new(0,180,0) then
game.ReplicatedStorage.Events.Rotation:FireServer(selected, -90)
elseif selected.Orientation == Vector3.new(0,-90,0) then
game.ReplicatedStorage.Events.Rotation:FireServer(selected, 0)
end
end
end
end)
So basically, you can only rotate it once per selection or what?? I am a bit confused by the issue here, but I may have a clue: axis2 is set to true but never to false in the code example, could that affect it?
I can only rotate it once when it is selected, after unselecting and selecting it i can rotate it again but only once, and axis2 is set to false when the mouse clicks something else but not the block.
I actually considered suggesting a simpler way but ended up not doing it, basically what I could suggest is:
-- // could put this at the start of the script
-- // ideally, in my opinion the services should be retrieved there
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Events = ReplicatedStorage:WaitForChild("Events")
------------------- ACTUAL FIX
local newCFrame = selected.CFrame * CFrame.Angles(0, math.pi / 2, 0)
-- // make pi negative to make it go in the opposite direction
local rotY = select(2, newCFrame:ToEulerAnglesXYZ())
Events.Rotation:FireServer(selected, math.deg(rotY))
Oh also, you should consider using an attribute to define the real CFrame (the CFrame it’s being tweened to) of the object! The reason why it went at 45 degree angles and such is because you tried to rotate it while it’s already being tweened, you could instead try using that attribute.