local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() enabled = true Mouse.KeyDown:connect(function(key) if not enabled then return end if key == "z" then --make and do a hit test along the ray local ray = Ray.new(Player.Character.Torso.CFrame.p, (Mouse.Hit.p - Player.Character.Torso.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, Player) local distance = (position - Player.Character.Torso.CFrame.p).magnitude local rayPart = Instance.new("Part", workspace) rayPart.Name = "RayPart" rayPart.BrickColor = BrickColor.new("Bright red") rayPart.Transparency = 0 rayPart.Anchored = false rayPart.CanCollide = true rayPart.TopSurface = Enum.SurfaceType.Smooth rayPart.BottomSurface = Enum.SurfaceType.Smooth rayPart.formFactor = Enum.FormFactor.Custom rayPart.Size = Vector3.new(5, 5, 5) rayPart.CFrame = CFrame.new(position, Player.Character.Torso.CFrame.p) * CFrame.new(0, 0, 0) local Woosh = Instance.new("BodyPosition") Woosh.maxForce = Vector3.new(math.huge, math.huge, math.huge) Woosh.position = Vector3.new(0, 0, distance) Woosh.Parent = rayPart end end)
This script is meant to fire the rayPart from my torso and to where my mouse is pointing whenever I press Z. However it fires from where ever my mouse is pointing to a random position instead. Please Fix This For Me.