Hi, I am trying to rotate a model I am trying to do it for so long but it isn’t working… but I am sure I have a RenderStepped event that is setting the PrimaryPart’s CFrame to the mouse position. so basically if I use an InputBegan event it won’t work because of the RenderStepped event I need help doing it, here is the code:
local Player = game.Players.LocalPlayer;
local Mouse = Player:GetMouse();
local ReplicatedStorage = game:GetService("ReplicatedStorage");
local Frame = script.Parent;
local UserInputService = game:GetService("UserInputService");
local Target = nil;
local rotatingAngle = 0;
local Place = ReplicatedStorage:WaitForChild("Place");
local IsDeleting = false;
local Items = ReplicatedStorage:WaitForChild("Items");
local IsPlacing = false;
local GridSize = 2;
local new;
local RunService = game:GetService("RunService");
for _, button in pairs(Frame:GetChildren()) do
if button:IsA("TextButton") and button.Name ~= "Delete" then
button.MouseButton1Click:Connect(function()
if IsPlacing == false and IsDeleting == false then
IsPlacing = true;
goodToPlace = nil
local clientItem = Items:FindFirstChild(button.Name)
if clientItem then
new = clientItem:Clone();
new.Parent = game.Workspace
for index, Part in pairs(new:GetChildren()) do
if Part ~= new.PrimaryPart and (Part.Name ~= "InsideToucher") then
print(Part.Name);
Part.Color = Color3.fromRGB(85, 170, 255)
Part.Transparency = 0.75;
end
Part.CanCollide = false;
end
end
runConnection = RunService.RenderStepped:Connect(function()
local Mouseray = Mouse.UnitRay
local castRay = Ray.new(Mouseray.Origin, Mouseray.Direction * 1000);
local ignoreList = {new, Player.Character}
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)
local pos = CFrame.new(math.floor(position.X / GridSize) * GridSize, position.Y + (new.PrimaryPart.Size.Y/2) - (0.03), math.floor(position.Z / GridSize) * GridSize)
new:SetPrimaryPartCFrame(pos)
connection = nil
connection = new.InsideToucher.Touched:Connect(function() end)
local touchingParts = new.InsideToucher:GetTouchingParts()
for i = 1, #touchingParts do
if not touchingParts[i]:IsDescendantOf(new) and touchingParts[i] ~= workspace.Baseplate then
for index, val in pairs(new:GetChildren()) do
val.Color = Color3.fromRGB(255, 0, 0)
end
goodToPlace = false;
else
goodToPlace = true;
for index, val in pairs(new:GetChildren()) do
val.Color = Color3.fromRGB(85, 170, 255)
end
end
end
end)
end
end)
end
end
Frame.Delete.MouseButton1Click:Connect(function()
if IsPlacing == false then
if IsDeleting == false then
IsDeleting = true;
local mouseCon
mouseCon = Mouse.Move:Connect(function()
if Mouse.Target then
if not Mouse.Target.Parent:IsA("Model") then
workspace.SelectionBox.Adornee = nil;
Target = nil;
elseif Mouse.Target.Parent:IsA("Model") then
workspace.SelectionBox.Adornee = Mouse.Target.Parent.PrimaryPart
Target = Mouse.Target.Parent
end
end
end)
Mouse.Button1Down:Connect(function()
if Target then
workspace.SelectionBox.Adornee = nil;
ReplicatedStorage.Delete:FireServer(Target)
Target = nil;
IsDeleting = false;
IsPlacing = false
mouseCon:Disconnect()
connection:Disconnect();
end
end)
end
end
end)
UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then
return
else
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if goodToPlace == true then
Place:InvokeServer(new.PrimaryPart.CFrame, new.Name)
runConnection:Disconnect();
IsPlacing = false;
goodToPlace = nil;
new:Destroy()
end
elseif input.KeyCode == Enum.KeyCode.R then
warn("Rotating");
new:SetPrimaryPartCFrame(new:GetPrimaryPartCFrame() * CFrame.Angles(0, math.rad(90), 0))
end
end
end)
Help is appreciated!!