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!
Make the object stay rotated
What is the issue? Include screenshots / videos if possible!
Whenever the object is rotated, it will instantly be refixed by runservice
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
None as of late
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!
-- local RunService = game:GetService("RunService")
local Placing = false
local Mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
script.Parent.MouseButton1Click:Connect(function()
local NewHouse = game.ReplicatedStorage.Placeables:FindFirstChild(script.Parent.Text):Clone()
Placing = true
NewHouse.Parent = workspace
local RStepped = RunService.RenderStepped:Connect(function()
local X = Mouse.Hit.X
NewHouse.CFrame = CFrame.new(X, NewHouse.Size.Y/2, Mouse.hit.Z)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
X = X * CFrame.Angles(90,0,0)
end
end)
end)
NewHouse.CanCollide = false
local function place()
Placing = false
RStepped:Disconnect()
local REvent = script.RemoteEvent
REvent:FireServer(NewHouse.CFrame)
NewHouse:Destroy()
end
local function notplace()
Placing = false
RStepped:Disconnect()
NewHouse:Destroy()
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
notplace()
end
end)
Mouse.Button1Down:Connect(function()
if Placing then
local Connection = NewHouse.Touched:Connect(function() end)
local TouchingParts = NewHouse:GetTouchingParts()
Connection:Disconnect()
if #TouchingParts < 1 then
place()
else
notplace()
end
end
end)
end)
You are continually setting the X variable back to Mouse.Hit.X each step of the RenderStepped, once you press R and multiply X * CFrame.Angles, almost inmediately X changes back to Mouse.Hit.X
I would try it like this:
(Creating a variable outiside the RenderStepped connection, and updating it when pressing R, and using that value to feed the CFrame.Angles() )
After 4 times pressing the R key, 90*4 would be 360° so, it would need you add an statement to restore that to 0 once it reached 360
local Xrot = 0
local Yrot = 0
local Zrot = 0
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
Yrot += 90
end
end)
local RStepped = RunService.RenderStepped:Connect(function()
local Xpos = Mouse.Hit.X
local Zpos = Mouse.hit.Z
NewHouse.CFrame = CFrame.new(Xpos, NewHouse.Size.Y/2, Zpos) * CFrame.Angles(math.rad(Xrot),math.rad(Yrot),math.rad(Zrot))
end)
EDIT: I forgot to mention, would be better if you take the InputBegan out from the RenderStepped loop, otherwise you would be connecting that Input thousand of times
It worked! I’m very grateful for you replying so quickly
My code:
local RunService = game:GetService("RunService")
local Placing = false
local Mouse = game.Players.LocalPlayer:GetMouse()
local UIS = game:GetService("UserInputService")
local XRot = 0
script.Parent.MouseButton1Click:Connect(function()
local NewHouse = game.ReplicatedStorage.Placeables:FindFirstChild(script.Parent.Text):Clone()
Placing = true
NewHouse.Parent = workspace
local RStepped = RunService.RenderStepped:Connect(function()
local XPos = Mouse.Hit.X
local ZPos = Mouse.Hit.Z
NewHouse.CFrame = CFrame.new(XPos, NewHouse.Size.Y/2, ZPos) * CFrame.Angles(math.rad(XRot), 0, 0)
end)
NewHouse.CanCollide = false
local function place()
Placing = false
RStepped:Disconnect()
local REvent = script.RemoteEvent
REvent:FireServer(NewHouse.CFrame)
NewHouse:Destroy()
end
local function notplace()
Placing = false
RStepped:Disconnect()
NewHouse:Destroy()
end
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
notplace()
end
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.R then
XRot += 90
end
end)
Mouse.Button1Down:Connect(function()
if Placing then
local Connection = NewHouse.Touched:Connect(function() end)
local TouchingParts = NewHouse:GetTouchingParts()
Connection:Disconnect()
if #TouchingParts < 1 then
place()
else
notplace()
end
end
end)
end)
A very genius solution that I probably would not have come up with, and I am grateful for it!