Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Set CFrame position without rotating?

When I click the mouse, the game spawns in a model to my mouse position but I dont know how to set the model's position to the mouse position without rotating the model. It's taken me ages to try figure it out but i cant get my head around Cframe.

local player = game.Players.LocalPlayer local mouse = player:GetMouse()

function place() local foundation = game.ReplicatedStorage.Foundation:Clone() foundation.Parent = game.Workspace local x, y, z = mouse.Hit:toEulerAnglesXYZ() foundation:SetPrimaryPartCFrame(mouse.Hit.Position * CFrame.fromEulerAnglesXYZ(-x,-y,-z)) end

mouse.Button1Up:connect(place)

1 comment

0

Can you put it in a code block please?

1 answer

I tried this myself and it seemed to work fine...but I am sure there are probably much easier ways to do it

local mouse = game.Players.LocalPlayer:GetMouse()

function place()
	local foundation = game.Workspace.Model
	local primPart = foundation.Part
	foundation.PrimaryPart = primPart
	foundation:SetPrimaryPartCFrame(primPart.CFrame + (mouse.Hit.p - primPart.CFrame.p))
end

mouse.Button1Up:connect(place)

This discussion is preserved as it was. New answers, comments, and votes are closed.