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

mouse Target Position?

How would I get mouse.Target position?


mouse.Button1Down:connect(function()
	pcall(function()
		print(mouse.Target)
		print(Target.p)
	local Lazor = Instance.new("Part",workspace.Base)
	Lazor.Size = Vector3.new(11,2,mouse.Target.p) --   I need it for this...
	Lazor.Name = "Lazor"
	while wait() do 
	Lazor.Position = Character.Torso
		break
		end
	end)
end)

P.S: Taslem this isn't spam.

1 comment

0

Well, he's right. It's not spam... Though I think someone else would be more qualified to answer this question, I stink when it comes to CFrames.

2 answers

First, that doesn't make sense. The z coordinate of Size isn't a position -- it's a length.

If you mean you want Lazor to stretch between the character's torso and where they are pointing, you could do this:

Lazor.Size = Vector3.new(2, 2, (from - to).magnitude )
-- As long as the distance from from to to.
Lazor.CFrame = CFrame.new(  (from + to) / 2, to )
 -- from the middle, looking at an end

Then from would be Character.Torso.Position and to would be...

Not mouse.Target.Position. mouse.Target is a part. Its position is the center of that part, not where you are pointing (so it would be very far away for large objects).

Use mouse.Hit.p to get the position the mouse is hovering over.

1 comment

0

Ooh, I never thought of using "(Position + Position) / 2", but now that I think about it, it makes perfect sense. Adding two numbers and halving the sum returns the number between them, so I do not know why I did not apply that logic to vectors.

Use Mouse.Hit.p or Mouse.Target.Position. And as for your script, there are a few incorrect things, like the size configuration and the position of the laser.

local Player=Game:service'Players'.localPlayer;
local Character=Player.Character;
local Mouse=Player:getMouse();
Mouse.Button1Down:connect(function()
	pcall(function()
		local Distance=(Character.Torso.Position - mouse.Hit.p).magnitude;--// The distance apart
		local Lazor = Instance.new("Part",workspace)
	    	Lazor.Size = Vector3.new(11,2,Distance) --   I need it for this...
	    	Lazor.Name = "Lazor"
	    	Lazor.Position = CFrame.new(Character.Torso.Position, mouse.Hit.p) --// Starts at the torso while pointing at the position, goes halfway there.
			* CFrame.new(0,0,distance / 2);--// BlueTaslem's method with adding the positions together and dividing it works as well.
		Instance.new('Explosion',Workspace).Position = mouse.Hit.p;
	end)
end)

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