local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local part = game.Workspace:WaitForChild("House1")
local Position = part:GetPivot()
local tweenService = game:GetService("TweenService")
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Parent = game.Workspace
local UIS = game:GetService("UserInputService")
local EV = game.ReplicatedStorage.Placing
local Xup = nil
local Zup = nil
local y = Position.Y
local OriX, OriZ, OriY = part:GetPivot():ToOrientation()
local canPlace = false
local function Move()
wait(0.25)
CFrameValue.Value = part:GetPrimaryPartCFrame()
local x,z = mouse.Hit.X, mouse.Hit.Z
Xup = math.floor(x / 4 + 0.5) * 4
Zup = math.floor(z / 4 + 0.5) * 4
local tweenInfo = TweenInfo.new(
0.25,
Enum.EasingStyle.Back,
Enum.EasingDirection.Out,
0,
false,
0
)
local tweenPart = tweenService:Create(CFrameValue, tweenInfo, {Value = CFrame.new(Xup,y,Zup)})
tweenPart:Play()
local filter = OverlapParams.new()
filter.FilterType = Enum.RaycastFilterType.Exclude
filter.FilterDescendantsInstances = {game.Workspace.Baseplate, player.Character, part}
local foundParts = workspace:GetPartsInPart(part.HitBox, filter)
if foundParts[1] ~= nil then
part.Highlight.FillColor = Color3.new(255,0,0)
canPlace = false
else
part.Highlight.FillColor = Color3.new(0,255,0)
canPlace = true
end
end
local function Rotate(input)
if input.KeyCode == Enum.KeyCode.R then
local rotation = CFrame.Angles(0, math.rad(90), 0)
local modelCFrame = part:GetPivot()
part:PivotTo(modelCFrame * rotation)
end
end
mouse.Button1Down:Connect(function()
if canPlace == true then
local Pos = Vector3.new(Xup,y,Zup)
local Ori = Vector3.new(OriX,OriY,OriZ)
print(OriX,OriY,OriZ)
EV:FireServer(Pos, Ori)
else
print("Cannot place here")
end
end)
CFrameValue:GetPropertyChangedSignal("Value"):connect(function()
part:SetPrimaryPartCFrame(CFrameValue.Value)
end)
mouse.Move:Connect(Move)
UIS.InputBegan:Connect(Rotate)
This is the code I am trying to make work but for some reason it does not work. (Sorry in advance if the variables have funny names)
I have gotten the tween to work and the rotate sort of works. The problem with the rotate is that you press R and it rotates but as soon as you move your mouse the rotate cancels and goes back to it’s original rotation. I know I am doing something wrong but I just don’t know what. If someone could also explain if their is an easier way to rotate a model than :pivotTo or explain more in depth about it that would be greatly appreciated!
Thanks, Hellobeede