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