Model won't set orientation right whenever its cloned infront of the player

Hello there users of devforum. I have come across a problem with my script of the model not being orientated right.

I have attempted to use math.deg, CFrame.angles or even just typing another TranslateBy but using math.deg. Yet none of these have worked so help would be great.

Im not showing the full script but it should be somewhere here.

if InsideCC == false then
				InsideCC = true
				if msg == "scp-2521" or "SCP-2521" or "2521" or "SCP 2521" or "scp 2521" then
					local char = player.Character
					local hrp = char:WaitForChild("HumanoidRootPart")	
					if hrp and char then	
						hrp.Anchored = true
						local clonedmodel = SCP2521:Clone()
						clonedmodel.Parent = workspace
						clonedmodel:SetPrimaryPartCFrame(hrp.CFrame)
						clonedmodel:TranslateBy(Vector3.new(2, 0, 2))
					else
						brick.Touched:Disconnect(function()
						InsideCC = false

just editting so this can be boosted x2

just use SetPrimaryPart with a cframe that’s offset with a rotation

e.g., :SetPrimaryPartCFrame(Part.CFrame * CFrame.new(0,0, -16) * CFrame.Angles(0, math.rad(30), 0) + Vector3.new(0, 15, 0))
this makes a cframe that’s 16 studs in front of Part, then rotates it 30 degrees to (I think) the left, then offsets it by 15 studs upwards globally

It didn’t seem to work and plus it doesn’t even show the cloned model

clonedmodel:SetPrimaryPartCFrame(clonedmodel.PrimaryPart.CFrame * CFrame.new(0,0, -16) * CFrame.Angles(0, math.rad(30), 0) + Vector3.new(0, 15, 0))

I can’t tell If I did something wrong or Im just having a hard time understanding

I see a few other issues in your code, like your boolean expression on the 3rd line not using or correctly, you putting arguments into :Disconnect that doesn’t take arguments, you checking if char exists after using :WaitForChild on it

so try adding breakpoints or prints around to make sure the code reaches the line where you’re setting the primary part cframe

image
Well it does reach the part of the cloning area

local clonedmodel = SCP2521:Clone()
						print("Model Cloned Succesfully")
						clonedmodel.Parent = workspace
						clonedmodel:SetPrimaryPartCFrame(clonedmodel.PrimaryPart.CFrame * CFrame.new(0,0, -16) * CFrame.Angles(0, math.rad(30), 0) + Vector3.new(0, 15, 0))
						clonedmodel:TranslateBy(Vector3.new(2, 0, 2))

you’re doing clonedmodel.PrimaryPart.CFrame * , so it would be 16 studs in front of its current cframe, not of your character

So Would I make another variable to set the primary part of the actual model?

local SCP2521PrimaryPart = SCP2521.PartThatIsPrimaryPart

Such as this?

no, in your case, you’d use the player’s humanoidRootPart’s cframe and offset that cframe to get the cframe you’d put into :SetPrimaryPartCFrame

image
Well It’s still sideways

clonedmodel:SetPrimaryPartCFrame(hrp.CFrame * CFrame.new(0,0, -16) * CFrame.Angles(0, math.rad(30), 0) + Vector3.new(0, 15, 0))

This bit is the bit that handles rotation, so mess around with the X Y and Z numbers in there until it is oriented correctly. They are all in radians, the function math.rad(30) converts 30 degrees into radians.

That’s not what or does. or allows you to check multiple expressions, it doesn’t allow you to compare multiple things to a single value. You need to re-write it like so:

if msg == "scp-2521" or msg == "SCP-2521" or msg == "2521" or msg =="SCP 2521" ...

It can also save you a little time if you use string.lower to ignore capitals:

if msg:lower()=="scp-2521" or msg:lower() == "scp 2521" or msg == "2521" then
1 Like

you need to change the values in each of the offsets
I was giving you an example of how to set it up with example values

1 Like

Alright I got it to work and stay in the right orientation. Thanks,