Placement system model not rotating

I’ve been stuck at this simple task for days: rotate the model, but it doesn’t for some reason, i’ve checked some answers in other questions, nothing worked, it’s a localscript inside the starter gui:
image
(it’s inside the Inventory frame btw, TextButton)

here is the code

local tower = nil
local isPlacing = false
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local deb = true
local del = 0.1
local curDec = nil
local currentPos = {["X"]= 0, ["Y"] = 0, ["Z"] = 0}

function sendRaycast(blacklist)
	local raypar = RaycastParams.new()
	raypar.FilterDescendantsInstances = blacklist
	raypar.FilterType = Enum.RaycastFilterType.Blacklist

	local Origin = mouse.UnitRay.Origin
	local direction = mouse.UnitRay.Direction * 1000

	local raycast = workspace:Raycast(Origin, direction, raypar)

	return raycast
end

function initDecoy()
	local dec = tower:Clone()
	dec.PrimaryPart.BrickColor = BrickColor.new("Really red")
	--local rc = sendRaycast({dec})
	--if rc then
	dec.Parent = workspace
	print("Success!")
	--dec:SetPrimaryPartCFrame(CFrame.new(rc.Position))
	return dec
end

for i, v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") then
		v.Activated:Connect(function()
			tower = v.Tower.Value
			curDec = initDecoy()
			isPlacing = true
		end)
	end
end

game:GetService("RunService").RenderStepped:Connect(function()
	if curDec == nil or isPlacing == false then return end
	local rc = sendRaycast({curDec, player.Character, game.Players:GetChildren(), workspace.Enemies:GetChildren()})
	if rc then
		local size = curDec:GetExtentsSize()
		local position = CFrame.new(rc.Position+Vector3.new(0,size.y/2, 0))
		
		curDec:SetPrimaryPartCFrame(position)
		
		currentPos.X = curDec.PrimaryPart.Position.X
		currentPos.Y = curDec.PrimaryPart.Position.Y
		currentPos.Z = curDec.PrimaryPart.Position.Z
	end
end)

uis.InputBegan:Connect(function(x)
	if curDec == nil or isPlacing == false then return end
	if x.KeyCode == Enum.KeyCode.R then
		--curDec.PrimaryPart.CFrame = curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/4, 0)
		curDec:SetPrimaryPartCFrame(curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))
	end	
	if x.KeyCode == Enum.KeyCode.Q then
		curDec:Destroy()
		curDec = nil
		tower = nil
		isPlacing = false
	end
	if x.UserInputType == Enum.UserInputType.MouseButton1 then
		if deb == true then 
			deb = false
			local ray = sendRaycast({curDec, player.Character, game.Players:GetChildren(), workspace.Enemies:GetChildren()})
			if ray then
				local t2 = curDec:Clone()
				t2.Name = "TestTower"
				t2.Parent = game.Workspace
				local calculatedPosition = CFrame.new(currentPos.X, currentPos.Y, currentPos.Z)
				t2:SetPrimaryPartCFrame(calculatedPosition)
				if uis:IsKeyDown(Enum.KeyCode.H) then
					t2.PrimaryPart.BrickColor = BrickColor.new("Bright blue")
				else
					curDec:Destroy()
					curDec = nil
					tower = nil
					t2.PrimaryPart.BrickColor = BrickColor.new("Bright blue")
					isPlacing = false
				end
				
			end
			task.wait(del)
			deb = true
		end
	end
end)

specifically, on line 62 - 65

if x.KeyCode == Enum.KeyCode.R then
		--curDec.PrimaryPart.CFrame = curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.pi/4, 0)
		curDec:SetPrimaryPartCFrame(curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))
	end	

if you need more info, please ask in the comments.

Thanks.

You might want to try changing the object’s Rotation property directly:

curDec.RootPart.Orientation += Vector3.new(0,90,0)

Would need to be the “Orientation” property for BasePart instances. This is also a model not a BasePart.

Oops! Oh yeah, I’m very sorry about that mistake. Thanks for pointing it out.
As a model, the RootPart’s Orientation could be changed.

curDec:SetPrimaryPartCFrame(curDec.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))

This should rotate the model 90 degrees along the Y axis, is it working as expected?

Sorry, i was sleeping, i wll now try your solution.

Nope, did not work.
30 ch aracters

Just unionize all the parts in the model, and use @bitsNbytez solution. That would probably be the easiest solution.

i cant, i’m going to put an entire humanoid inside of the model, i cant unionize a humanoid.

curDec:SetPrimaryPartCFrame(curDec:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(0, 90, 0))
1 Like

i tried it, it still doesnt work.

Errors?

Summary

This text will be hidden

the strange part is, that there is no error, it just doesnt rotate, the Q (destroy) and mouse button (place) functions seem to be working fine, just not the rotate function.

Try adding a print below the rotate part.

I’ve even tried that, it printed, but did not rotate.

So everything looks fine with it, try using it IN an actual game instance, instead of play testing it if you can, or if you haven’t yet.

Okay, i will try it.
30 ch aracters

I didn’t change the code by the way, I was just copying the line from your script.

i tried it, it did not work.
30 c hars

So either your script is broken, which is highly unlikely, or Roblox is broken.

1 Like