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

how would i get the cframe of the mouse? I really need it: [Solved by original poster]

uh, so i made a thing where you can rotate a scrollpaper by moving your mouse and holding it down.

It's erroring, since it requires a CFrame, thingy..

It's in a ViewPortFrame, and the currentcamera for it is in the workspace but the scroll is parented to the viewport frame

local mouse = game.Players.LocalPlayer:GetMouse()
local moving = false
local pressed = false

local runService = game:GetService("RunService")

mouse.Button1Down:Connect(function()
	
	pressed = true
end)

mouse.Move:Connect(function()
	
	moving = true
end)

mouse.Button1Up:Connect(function()
	
	pressed = false
	moving = false
end)

runService.RenderStepped:Connect(function()
	if moving and pressed then
		script.Parent.MeshPart.CFrame = script.Parent.MeshPart.CFrame * CFrame.new(math.rad(mouse.Hit.p.X), math.rad(mouse.Hit.p.Y), 0)
	end
end)

4 comments

0

hmm so what exactly are you using this for im a bit confused

0

Mouse.Hit.

0

What are you trying to say about mouse.hit??

0

Mouse.Hit correlates to the CFrame. Though most use it to reference the Positional component ".p/.Position.".

1 answer

(Feahren helped me understand a bit of what i should do) ~

I solved the original post, for anyone who was interested, i made a horror game, and there's a note. I noticed how people can read things from different perspectives. So when you hold your mouse down and move it you can rotate it to the angle you're comfortable with.

local mouse = game.Players.LocalPlayer:GetMouse()
local moving = false
local pressed = false

local runService = game:GetService("RunService")

mouse.Button1Down:Connect(function()
	
	pressed = true
end)

mouse.Move:Connect(function()
	
	moving = true
end)

mouse.Button1Up:Connect(function()
	
	pressed = false
	moving = false
end)

while wait() do
	
	if moving == true and pressed == true then
		local x1 = mouse.X
		local y1 = mouse.Y
		
		script.Parent.MeshPart.CFrame = script.Parent.MeshPart.CFrame * CFrame.Angles(math.rad(x1),math.rad(y1), 0)
	end
end

Basically, my error was i was inputting the incorrect value, i inserted a Vector3Value instead of a CFrame value, so i needed to change it to Mouse.Hit or Mouse.Y or Mouse.X, Mouse.Z is nonexistent, so there's no need for that.

Another mistake i made was that i put CFrame.new instead of CFrame.Angles, yeah. I learned quite a bit i can remember next time.

Thank you for reading and i hope you learned something.

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