So I’m a beginner programmer that is looking to expand my knowledge of programming. So I picked a simple idea that covers all the stuff I want to get better at remote events and back end scripting. The idea is a grid building system that saves the location of where it is placed. I spent about 3 coding and research sessions on this project and so far I still haven’t figured out how to make my model rotate. I spent hours on the developer hub trying to find a solution by using CFrame and eventually got it to work for a single part, not a model. My problem is that I can’t get the whole model to rotate, and tried many methods like getting all the parts of the model using :GetChildren(). None of these work. So If you have anything that could help me, please comment below.
Here is the code so far
local couch = game.ReplicatedStorage.LoveSeat:Clone()
couch.Parent = workspace
local posX
local posY
local posZ
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 4
local orientation
function snap()
posX = math.floor(mouse.Hit.X / grid + .5)* grid
posY = couch.PrimaryPart.Position.Y
posZ = math.floor(mouse.Hit.Z / grid + .5)* grid
end
function moveObject()
mouse.TargetFilter = couch
snap()
couch:SetPrimaryPartCFrame(CFrame.new(posX,posY,posZ))
end
function click()
local newCouch = couch:Clone()
newCouch.Parent = workspace
end
function rotate()
orientation = orientation + 45
couch:SetPrimaryPartCFrame(CFrame.new(couch.PrimaryPart.Position) * CFrame.Angles(0,math.rad(orientation), 0))
end
mouse.Move:Connect(moveObject)
mouse.Button1Down:Connect(click)
mouse.WheelForward:Connect(rotate())
rotate function is the one I need help with, and please don’t ask why I’m using scroll wheel to rotate