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

Is there any math I can use that could align the mouse with the mesh part??

So I have a basic script:

local plr = game.Players.LocalPlayer
spawn(function()
	game:GetService('RunService').Stepped:Connect(function()
		local m = plr:GetMouse()
		print(m.Hit.p)
		workspace.SawBlade.Position = Vector3.new(m.Hit.p.X,m.Hit.p.Y,92)
	end)
end)

It is suppose to take the SawBlade and put it on the mouse cursor then it is suppose to move the saw to Vector3.new(m.Hit.p.X,m.Hit.p.Y,92) but in doing so 92 isn't part of the mouses coordinate and when I move the mouse anywhere, the model lags behind it but the cursor doesn't, is there any math to fix it? I tried multiplying it by .001 even larger values and smaller but the model simply vanishes...

Help please..?

By lag I mean the everything is smooth but the model goes half the direction from the center to the mouse.

3 comments

2

mouse.Move

0

Should probably answer with that, Elixcore

0

That isn't the question Ankur... That isn't the answer Elixcore

2 answers

One thing you could do to fix lag a bit is to switch the mouse reference to the top of the script, another thing you can do is remove the print part because your computer or server will slow down quite a bit if it must print once every tick.

Another thing @Elixcore mentioned was using mouse.Move. mouse.Move fires each time the player moves his or hers mouse cursor.

local plr = game.Players.LocalPlayer
local m = plr:GetMouse()
m.Move:connect(function()
        workspace.SawBlade.Position = Vector3.new(m.Hit.p.X,m.Hit.p.Y,92)
end)

All of this together should optimize your code a bit and will most likely fix your problem entirely.

4 comments

0

Won't work... I wasn't asking for efficiency, I was asking for math that would double to mouse cursor so like m.Hit.p.X*2 except that makes the entire model disappear

0

Also the entire model glitches when this happens. it vanishes then comes back..

0

why 92 for Z value?

0

its the distance from the camera to where the Z of the player is

Oh yeah, alternative title since I'm just coming back to my old posts for fun. "How to create a plane for the mouse to move objects on without the vector world interference" or something like that.

I solved this by stealing code from devforum

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