Rotation not changing on script

On the MouseDown event, when i print out the CFrames and the Rotation, it’s always 0,0,0. Am I missing something?
The Rotation applies to the actual model, but when i print the values it’s wrong.

toSpawn is an Instance: Model

mouse.Button1Down:Connect(function()
	if toSpawn then
		assert(toSpawn:IsA("Model"))
		print(toSpawn:GetPivot())
		print(toSpawn.PrimaryPart.CFrame)
		print(toSpawn.PrimaryPart.Rotation)
		
		ReplicatedStorage.Events.Place:FireServer(toSpawn.Name, toSpawn:GetPivot())
		destroyPlaceholder()
	end
end)

the output:

14:49:51.829  -48.8549271, 0, 11.1064882, 1, 0, 0, 0, 1, 0, 0, 0, 1  -  Client - LocalScript:87
14:49:51.830  -48.8549271, 0, 11.1064882, 1, 0, 0, 0, 1, 0, 0, 0, 1  -  Client - LocalScript:88
14:49:51.830  0, 0, 0  -  Client - LocalScript:89
2 Likes

Is the rotation of the model’s PrimaryPart in properties outside of the script 0,0,0?

2 Likes

Yeah, I see it with a different rotation than the one it shows in the output

1 Like

Have you tried printing it on the server end to see if its just a client end issue?

1 Like

The script should work only on the client though, it’s for a placement system so i can’t try it on the server ):

You should be able to print it on the server I would think but if you can’t i’d try rotating the model outside of the script and seeing if it changes, otherwise no harm in having the server rotate it to 0,0,0 or client do it just so it can be 100% accurate at 0,0,0

I have an event to make the user able to rotate the model with the R key, so i don’t want it constantly at 0,0,0.

it rotates visually but not on the script, like the video

Can i see your rotate event? Maybe the issue is in there

local function rotateModel(degrees)
	assert(toSpawn:IsA("Model"))
	local primaryPart = toSpawn.PrimaryPart
	if primaryPart then
		primaryPart.CFrame = primaryPart.CFrame * CFrame.Angles(0, math.rad(degrees), 0)
	end
end

uis.InputBegan:Connect(function(input, proc)
	if proc then return end
	if input.KeyCode == Enum.KeyCode.R then
		if toSpawn then
			rotateModel(45)
		end
	end
	if input.KeyCode == Enum.KeyCode.T then
		if toSpawn then
			rotateModel(-45)
		end
	end
end)

here!

So thats rotating the display preview if I’m reading it right correct?

yes, that model is stored in the “toSpawn” variable

  1. The assert function is used to detect errors, but it’s not required in this situation, you could better just

“return” if toSpawn variables is not model.

if not (toSpawn:IsA('Model')) then return end
  1. The problem could be cause of you edit pivot of selected model, you could better use GetBoundingBox() function.

Can you show me the spawning event? My guess is the preview is rotating but the rotational data isn’t being transferred to the spawned model

It looks like it doesn’t have any rotation to it.

-48.8549271, 0, 11.1064882, 1, 0, 0, 0, 1, 0, 0, 0, 1 

Your rotation matrix is
{1,0,0}
{0,1,0}
{0,0,1}

ie, the part isn’t rotated

Try doing Model:SetPrimaryPartCFrame(). I think you’re just moving the primaryPart around by itself, right now.

Also, you should be a little more consistent with the instances you’re checking. Instead of switching from primarypart to model, why not stick with the primarypart?

i was using assertion for code suggestions, i will remove them afterwards, thanks

also can you help me on how to use the getboundingbox function? sorry, i’ve never used it.

mouse.Button1Down:Connect(function()
	if toSpawn then
		local cf = toSpawn:GetPivot()
		print(cf)
		
		ReplicatedStorage.Events.Place:FireServer(toSpawn.Name, cf)
		destroyPlaceholder()
	end
end)

@kom297 this is the placing function i’m using

of course. The GetBoundingBox() function returns size and orientation of model. (Bounding box)

for ex.

local Orientation, Size = toSpawn:GetBoundingBox()

warn('Orientation of model is: ' .. Orientation) -- for ex -17, 0, 25

have you tried using toSpawn.CFrame as the cf variable?

oh, this is it.
it works with SetPrimaryPartCFrame!

thanks to you all, i will try to work with GetBoundingBox too.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.