Cant rotate union/part on the x axis via script ):

The code your going to see is somewhat complicated, messy, and possibly confusing. But what I’m trying to do is basically make a build system, where at the final function of the script, has part = hitsize (hitsize is a clone of a union). The original union has an orientation of 90,0,0, but the clone has an orientation of 0,0,0, and it seems that as hard as I try, I can’t change the x axis orientation of the part. But I can change the y axis rotation easily as seen in the code when I press the r key it rotates just fine. But for some reason, I can’t force it to rotate back to 90 degrees on the x axis. I’m probably confusing you as you read this, I’m not sure if I have provided enough info, probably not, but if you have any questions just ask.

But I believe there is something in the local script that resets the x axis to 0. Soo IS THERE ANYTHING IN THE CODE THAT COULD POSSIBLY AFFECT THIS

local tool = script.Parent


local gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("BuildSystemGui")

local event3 = game.ReplicatedStorage.SizeChanger

local part = game.ReplicatedStorage.BuildStorage.DefaultView
part.Transparency = 0.5
part.Color = Color3.new(0, 1, 0)
part.Size = Vector3.new(3,3,3)
part.Anchored = true 
part.Parent = nil 
part.CanCollide = false


local offset = Vector3.new(0, part.Size.y/2, 0)


local isRotating = false

local function updatePosition()
	if not isRotating then
		local mouse = game.Players.LocalPlayer:GetMouse()
		local hitPos = mouse.Hit.p
		local ray = Ray.new(hitPos + offset, Vector3.new(0, -10, 0))
		local partObj, pos = workspace:FindPartOnRayWithIgnoreList(ray, {part})
		if partObj then
			part.CFrame = CFrame.new(pos + offset, pos + offset + (part.CFrame.lookVector * Vector3.new(1, 0, 1)))



			local playerPos = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
			if (part.Position - playerPos).magnitude > 20 then
				
				part.Color = Color3.new(1, 0, 0)
			else
				part.Color = Color3.new(0, 1, 0) 
			end
		end
	end
end


local function onEquipped()
	gui.Enabled = true
	part.Transparency = 0.5

	isRotating = false
	


	

	tool.Activated:Connect(function(clicked)
		if part.Color == Color3.new(0, 1, 0) then
			local mouse = game.Players.LocalPlayer:GetMouse()
			local pos = part.Position
			local rotation = part.Orientation
			print(rotation)
			game.ReplicatedStorage.Build:FireServer(pos, rotation)
		else
			print("not in range")
		end
	end)
end


local function onUnequipped()
	gui.Enabled = false
	part.Transparency = 1 
end


tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)

while not tool:IsA("Tool") do
	tool = tool.Parent
	wait()
end

local bKeyPressed = false
game:GetService("UserInputService").InputBegan:Connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.B and not gameProcessed then
		bKeyPressed = not bKeyPressed 
		if bKeyPressed then
			part.Parent = workspace.Terrain
			updatePosition()
		else
			part.Parent = nil 
		end
		
	end
end)


local prevPos = part.Position
local prevTime = tick()
local updateTime = 1/120 
game:GetService("RunService").Heartbeat:Connect(function(dt)
	if bKeyPressed then
		local currTime = tick()
		if currTime - prevTime >= updateTime then
			updatePosition()
			local currPos = part.Position
			local velocity = (currPos - prevPos) / (currTime - prevTime)
			part.Velocity = velocity
			prevPos = currPos
			prevTime = currTime
		end
	else
		part.Velocity = Vector3.new()
	end
end)


local UserInputService = game:GetService("UserInputService")

local function onInput(input, gameProcessedEvent)
	
	if input.KeyCode == Enum.KeyCode.R and gameProcessedEvent == false then
		while UserInputService:IsKeyDown(Enum.KeyCode.R) do
		
			part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(3), 0)
			wait()
		end
		print("The R key is no longer being held down.")
	end
end

UserInputService.InputBegan:Connect(onInput)

event3.OnClientEvent:Connect(function(hitsize)
	print(hitsize.Orientation)
	part.Orientation = hitsize.Orientation
	print(part.Orientation)
	part = hitsize
	print(part.Orientation)

	local relativeRotation = CFrame.Angles(math.rad(90), 0, 0)
	part.CFrame = hitsize.CFrame * relativeRotation
	part.Transparency = .5
	print(part.CFrame.lookVector)
end)

Oh gosh I’ve been trying to figure this out for hoooursss

ahhhhhhhhhhhHHhhhhhhhhh

1 Like

which variable has a 0 x axis? (i dont see any clone function)

2 Likes

Clone function is coming from a server script that is sending over hitsize, which is the clone of something. Which is why you see part being redifined as hitsize. But originally the clone has an orientation of 90,0,0, but then once part becomes hitsize then the rotation resets to 0,0,0 (but I can still change the y axis rotation), but not x axis rotation.

Also sorry for the late reply

“something” has the orientation of 90,0,0?

Why is its name important…? it has an orientation of 90,0,0, because if it doesn’t it looks like its flipped over, (It’s a barricade, its clone is supposed to become part to show where your placing the barricade down, this is a placement system I should have probably mentioned that in the original post)

yeah you said “of something”

btw try removing the lines:

local relativeRotation = CFrame.Angles(math.rad(90), 0, 0)
part.CFrame = hitsize.CFrame * relativeRotation

see if it’s still the same or not.

It still has a x axis rotation of 0. I still believe its something else in the local script that may be resetting it to 0

can you screenshot the output when running the script?

Sure, there are no errors but you will see when print statements print 90,0,0, and when they start not printing that:
image
Notice at the start it is 0,0,0, which is fine because the part hasn’t been set to hitsize yet. But after I click the button that triggers the change, notice clicked, it prints it is 90,0,0, but then it prints it is 0,0,0. Which means when the function ran its course, the part switched back to 0,0,0, which makes me believe something else in the script is resseting it

sorry but your script only has 145 lines, that last line of the output has line 153

Oh ya my bad, those last lines is just a while true do loop that prints the orientation of the part, forgot to add that part to the script in my og post

ok but can u send the script too?

Uh sure, it just runs separately from the rest of the script though

while true do
	wait(1)
	print(part.Orientation)

end

ok next question, are you supposed to see hitsize or part instance from the script you sent earlier before the while loop

Part starts out as a 3,3,3 part, but is redifined as hitsize. So the script is only printing the orientation of part, since part becomes hitsize as you can see in the script

can you screenshot your gameplay showing the hitsize instance

Sorry for the late reply, again
But this me trying to place it down, but it isn’t rotated on the x axis 90 degrees
image
But I can easily rotate it on the y axis with the r key
image

sorry for the late response too, is it supposed to be rotated 90 degrees without any user interaction? also, when you attempted to change the x axis from the script nothing happened?

It isn’t suppoed to be by user ineteraction, im just pointing out I can rotate tit, but for some reason not on the x axis. And yes I can’t change the x axis rotation by script

can you invite me to teamcreate so i dont waste my time typing