Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 3 days ago
Edited 3 days ago

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)

0
hmm so what exactly are you using this for im a bit confused DuckyRobIox 180 — 3d
0
Mouse.Hit. Feahren 5485 — 3d
0
What are you trying to say about mouse.hit?? CaIcuIati0n 163 — 3d
0
Mouse.Hit correlates to the CFrame. Though most use it to reference the Positional component ".p/.Position.". Feahren 5485 — 3d

### 1 answer

Log in to vote
0
Answered by 3 days ago
Edited 3 days ago

(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.