I want to make the Display part go on top the of the target but instead it goes inside of it how,would I fix this and why does it do it?
Tool = script.Parent Handle = Tool.Handle Player = game.Players.LocalPlayer Camera = game.Workspace.CurrentCamera --------------------------------- function CreateDisplayPart()--Creates DisplayPart local DisPart = Instance.new("Part",Camera)--Hides it from players DisPart.Anchored = true DisPart.CanCollide = false DisPart.Transparency = 0.5 DisPart.Name = "DisplayPart" DisplayPart = DisPart end --------------------------------- Tool.Equipped:connect(function(Mouse) --------------------------------- DisplayPart = Camera:FindFirstChild("DisplayPart") if not DisplayPart then--If not found then makes it CreateDisplayPart() end Mouse.Move:connect(function() Mouse.TargetFilter = DisplayPart if Mouse.Target then --If not nil then do the following DisplayPart.CFrame = CFrame.new(Mouse.Hit.p)* CFrame.new(Mouse.Target.CFrame.p) end end) end)
The problem is that you're using the CFrame
of the Mouse.Hit
and Mouse.Target
. Those two are going to force you straight into the Mouse.Target
. Here's a better way to write line 24
:
DisplayPart.CFrame = CFrame.new(Mouse.Target.Position) * CFrame.new(Vector3.new(0, (Mouse.Target.Size.Y / 2) + (DisplayPart.Size.Y / 2), 0)
Keep in mind that this will not work for Parts
that are tilted. For that, you'll need a more complex algorithm, and I don't know that I'd be able to figure that out. I'd suggest not going here for that, if you need it, but rather, find a math forum such as this.