I’m creating a placing system and want to make it tween when clicking r to rotate i aleardy created the rotating feature but i’m not sure how i’m supposed to tween it.
here is a snippet of the code
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
Mouse.TargetFilter = PrieviewObject
--checks the preiviewobject childeren to find the mainpart
if PrieviewObject:FindFirstChild("MainPart") then
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y+ PrieviewObject.PrimaryPart.Size.Y/2,Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmounts),0)
PrieviewObject:SetPrimaryPartCFrame(ObjectCFrame, ObjectAngles)
local part = Instance.new("Part") -- I made a part to tween, you can delete this part
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(-15.627, 7.385, -1.076)
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.3, -- your time here(make it a really low time because it freezes the movement a bit)
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local objectCFrame = part.CFrame --change this
local ObjectAngles = CFrame.Angles(0,math.rad(90),0) --put custom amount
local tween = TweenService:Create(part, tweenInfo, {CFrame = CFrame.new(part.Position)*ObjectAngles})
tween:Play()
you need to multiply it so the position is the same, if you don’t do it I think it breaks because you can’t change the CFrame orientation, you need to do both at the same time.
--Game Services
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
local TweenService = game:GetService('TweenService')
--Events
local PlacementEvent = RepStorage.PlacementEvent
--folders
local ComputerFolder = RepStorage:WaitForChild('ComputerFolder')
local CoderFolder = RepStorage:WaitForChild('ProgrammerFolder')
local CFolder = Instance.new('Folder')
CFolder.Name = "ComputerFolders"
CFolder.Parent = workspace
--Player Refrences
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
--Gui ELements
local PlayerInv = script.Parent:WaitForChild('PlayerInvFrame')
local ScrollingFrame = PlayerInv:WaitForChild('ScrollingFrame')
local ObjectFrame = ScrollingFrame:WaitForChild('ObjectFrame')
local PlayerInvOutline = script.Parent:WaitForChild("PlayerInvFrameShade")
--Booleans
local PlacingObject = false
local RotatingObject = false
for i, v in pairs(ObjectFrame:GetChildren()) do
if v:IsA('TextButton') then
v.MouseButton1Click:Connect(function()
PlayerInv.Visible = false
PlayerInvOutline.Visible = false
PlacingObject = true
if PlacingObject == true then
local PrieviewObject = ComputerFolder:FindFirstChild(v.Name):Clone()
PrieviewObject.Parent = CFolder
local RotationAmounts = 0
for i,Obj in pairs(PrieviewObject:GetDescendants()) do
if Obj:IsA("BasePart") then
Obj.CanCollide = false
end
end
UIS.InputBegan:Connect(function(Key, GameProccesed)
if not GameProccesed then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
if RotatingObject == true then
RotationAmounts += 90
end
end
end
end)
UIS.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
Mouse.TargetFilter = PrieviewObject
--checks the preiviewobject childeren to find the mainpart
if PrieviewObject:FindFirstChild("MainPart") then
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.3, -- your time here(make it a really low time because it freezes the movement a bit)
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y+ PrieviewObject.PrimaryPart.Size.Y/2,Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmounts),0) --put custom amount
local tween = TweenService:Create(PrieviewObject:FindFirstChild('MainPart'), tweenInfo, {CFrame = CFrame.new(PrieviewObject:FindFirstChild('MainPart').Position)*ObjectAngles})
tween:Play()
PrieviewObject:SetPrimaryPartCFrame(ObjectCFrame, tween)
PrieviewObject:FindFirstChild("MainPart").Touched:Connect(function()
PrieviewObject:FindFirstChild("CantPlace").Transparency = 0.9
PrieviewObject:FindFirstChild("MainPart").Transparency = 1
end)
end
end
end)
Mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
PlacementEvent:FireServer(PrieviewObject.Name, PrieviewObject.PrimaryPart.CFrame)
PrieviewObject:FindFirstChild("MainPart"):Destroy()
PrieviewObject:FindFirstChild("CantPlace"):Destroy()
end
end)
end
end)
end
end
I think I finally got it, I added a debounce because its running too fast, here is another version(you might need to edit it a bit more)
local debouncePlace = false
if PlacingObject == true and debouncePlace == false then
debouncePlace = true
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(-15.627, 7.385, -1.076)
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
2, -- your time here
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local objectCFrame = part.CFrame --change this
local ObjectAngles = CFrame.Angles(0,math.rad(90),0) --put custom amount
local tween = TweenService:Create(part, tweenInfo, {CFrame = CFrame.new(part.Position)*ObjectAngles})
tween:Play()
wait(1)
debouncePlace = false
end
I have an error PlayerGui.ScreenGui.PlacmentSys:90:attempt to perform arithmetic (mul) on Instance - Client - PlacmentSys:90
--Game Services
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
--Events
local PlacementEvent = RepStorage.PlacementEvent
--folders
local ComputerFolder = RepStorage:WaitForChild('ComputerFolder')
local CoderFolder = RepStorage:WaitForChild('ProgrammerFolder')
local CFolder = Instance.new('Folder')
CFolder.Name = "ComputerFolders"
CFolder.Parent = workspace
--Player Refrences
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
--Gui ELements
local PlayerInv = script.Parent:WaitForChild('PlayerInvFrame')
local ScrollingFrame = PlayerInv:WaitForChild('ScrollingFrame')
local ObjectFrame = ScrollingFrame:WaitForChild('ObjectFrame')
local PlayerInvOutline = script.Parent:WaitForChild("PlayerInvFrameShade")
--Booleans
local PlacingObject = false
local RotatingObject = false
for i, v in pairs(ObjectFrame:GetChildren()) do
if v:IsA('TextButton') then
v.MouseButton1Click:Connect(function()
PlayerInv.Visible = false
PlayerInvOutline.Visible = false
PlacingObject = true
if PlacingObject == true then
local PrieviewObject = ComputerFolder:FindFirstChild(v.Name):Clone()
PrieviewObject.Parent = CFolder
local RotationAmounts = 0
for i,Obj in pairs(PrieviewObject:GetDescendants()) do
if Obj:IsA("BasePart") then
Obj.CanCollide = false
end
end
UIS.InputBegan:Connect(function(Key, GameProccesed)
if not GameProccesed then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
if RotatingObject == true then
RotationAmounts += 90
end
end
end
end)
UIS.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
local debouncePlace = false
if PlacingObject == true and debouncePlace == false then
debouncePlace = true
if PrieviewObject:FindFirstChild("MainPart") then
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.5, -- your time here
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y+ PrieviewObject.PrimaryPart.Size.Y/2,Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmounts),0) --put custom amount
local tween = TweenService:Create(PrieviewObject:FindFirstChild('MainPart'), tweenInfo, {CFrame = CFrame.new(PrieviewObject:FindFirstChild('MainPart').Position)*ObjectAngles})
tween:Play()
PrieviewObject:SetPrimaryPart(ObjectFrame * tween)
debouncePlace = false
PrieviewObject:FindFirstChild("MainPart").Touched:Connect(function()
PrieviewObject:FindFirstChild("CantPlace").Transparency = 0.9
PrieviewObject:FindFirstChild("MainPart").Transparency = 1
end)
end
end
end)
Mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
PlacementEvent:FireServer(PrieviewObject.Name, PrieviewObject.PrimaryPart.CFrame)
PrieviewObject:FindFirstChild("MainPart"):Destroy()
PrieviewObject:FindFirstChild("CantPlace"):Destroy()
end
end)
end
end)
end
end
--Game Services
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
--Events
local PlacementEvent = RepStorage.PlacementEvent
--folders
local ComputerFolder = RepStorage:WaitForChild('ComputerFolder')
local CoderFolder = RepStorage:WaitForChild('ProgrammerFolder')
local CFolder = Instance.new('Folder')
CFolder.Name = "ComputerFolders"
CFolder.Parent = workspace
--Player Refrences
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
--Gui ELements
local PlayerInv = script.Parent:WaitForChild('PlayerInvFrame')
local ScrollingFrame = PlayerInv:WaitForChild('ScrollingFrame')
local ObjectFrame = ScrollingFrame:WaitForChild('ObjectFrame')
local PlayerInvOutline = script.Parent:WaitForChild("PlayerInvFrameShade")
--Booleans
local PlacingObject = false
local RotatingObject = false
for i, v in pairs(ObjectFrame:GetChildren()) do
if v:IsA('TextButton') then
v.MouseButton1Click:Connect(function()
PlayerInv.Visible = false
PlayerInvOutline.Visible = false
PlacingObject = true
if PlacingObject == true then
local PrieviewObject = ComputerFolder:FindFirstChild(v.Name):Clone()
PrieviewObject.Parent = CFolder
local RotationAmounts = 0
for i,Obj in pairs(PrieviewObject:GetDescendants()) do
if Obj:IsA("BasePart") then
Obj.CanCollide = false
end
end
UIS.InputBegan:Connect(function(Key, GameProccesed)
if not GameProccesed then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
if RotatingObject == true then
RotationAmounts += 90
end
end
end
end)
UIS.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
local debouncePlace = false
if PlacingObject == true and debouncePlace == false then
debouncePlace = true
if PrieviewObject:FindFirstChild("MainPart") then
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.5, -- your time here
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y+ PrieviewObject.PrimaryPart.Size.Y/2,Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmounts),0) --put custom amount
local tween = TweenService:Create(PrieviewObject:FindFirstChild('MainPart'), tweenInfo, {CFrame = CFrame.new(PrieviewObject:FindFirstChild('MainPart').Position)*ObjectAngles})
tween:Play()
wait(1)
debouncePlace = false
PrieviewObject:FindFirstChild("MainPart").Touched:Connect(function()
PrieviewObject:FindFirstChild("CantPlace").Transparency = 0.9
PrieviewObject:FindFirstChild("MainPart").Transparency = 1
end)
end
end
end)
Mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
PlacementEvent:FireServer(PrieviewObject.Name, PrieviewObject.PrimaryPart.CFrame)
PrieviewObject:FindFirstChild("MainPart"):Destroy()
PrieviewObject:FindFirstChild("CantPlace"):Destroy()
end
end)
end
end)
end
end
The Prieviewobject:SetPrimaryPart was the part that made it so the object followed the cursor also im very sorry i keep getting errors im not good at scripting
--Game Services
local RepStorage = game:GetService("ReplicatedStorage")
local UIS = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
--Events
local PlacementEvent = RepStorage.PlacementEvent
--folders
local ComputerFolder = RepStorage:WaitForChild('ComputerFolder')
local CoderFolder = RepStorage:WaitForChild('ProgrammerFolder')
local CFolder = Instance.new('Folder')
CFolder.Name = "ComputerFolders"
CFolder.Parent = workspace
--Player Refrences
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Mouse = player:GetMouse()
--Gui ELements
local PlayerInv = script.Parent:WaitForChild('PlayerInvFrame')
local ScrollingFrame = PlayerInv:WaitForChild('ScrollingFrame')
local ObjectFrame = ScrollingFrame:WaitForChild('ObjectFrame')
local PlayerInvOutline = script.Parent:WaitForChild("PlayerInvFrameShade")
--Booleans
local PlacingObject = false
local RotatingObject = false
for i, v in pairs(ObjectFrame:GetChildren()) do
if v:IsA('TextButton') then
v.MouseButton1Click:Connect(function()
PlayerInv.Visible = false
PlayerInvOutline.Visible = false
PlacingObject = true
if PlacingObject == true then
local PrieviewObject = ComputerFolder:FindFirstChild(v.Name):Clone()
PrieviewObject.Parent = CFolder
local RotationAmounts = 0
for i,Obj in pairs(PrieviewObject:GetDescendants()) do
if Obj:IsA("BasePart") then
Obj.CanCollide = false
end
end
UIS.InputBegan:Connect(function(Key, GameProccesed)
if not GameProccesed then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = true
if RotatingObject == true then
RotationAmounts += 90
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.5, -- your time here
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y+ PrieviewObject.PrimaryPart.Size.Y/2,Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmounts),0) --put custom amount
local tween = TweenService:Create(PrieviewObject:FindFirstChild('MainPart'), tweenInfo, {CFrame = CFrame.new(PrieviewObject:FindFirstChild('MainPart').Position)*ObjectAngles})
tween:Play()
wait(1)
end
end
end
end)
UIS.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
local debouncePlace = false
if PlacingObject == true then
if PrieviewObject:FindFirstChild("MainPart") then
local ObjectCFrame = CFrame.new(Mouse.Hit.Position.X,Mouse.Hit.Position.Y+ PrieviewObject.PrimaryPart.Size.Y/2,Mouse.Hit.Position.Z)
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmounts),0) --put custom amount
PrieviewObject:SetPrimaryPartCFrame(ObjectCFrame, ObjectAngles)
PrieviewObject:FindFirstChild("MainPart").Touched:Connect(function()
PrieviewObject:FindFirstChild("CantPlace").Transparency = 0.9
PrieviewObject:FindFirstChild("MainPart").Transparency = 1
end)
end
end
end)
Mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
PlacementEvent:FireServer(PrieviewObject.Name, PrieviewObject.PrimaryPart.CFrame)
PrieviewObject:FindFirstChild("MainPart"):Destroy()
PrieviewObject:FindFirstChild("CantPlace"):Destroy()
end
end)
end
end)
end
end