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 local Shot = Instance.new("Part", workspace) Shot.Name = "RayPart" Shot.BrickColor = BrickColor.new("Bright red") Shot.Transparency = 0 Shot.Anchored = false Shot.CanCollide = false Shot.TopSurface = Enum.SurfaceType.Smooth Shot.BottomSurface = Enum.SurfaceType.Smooth Shot.formFactor = Enum.FormFactor.Custom Shot.Size = Vector3.new(5, 5, 5) Shot.CFrame = Player.Character.Torso.CFrame*CFrame.new(0,0,0) local Woosh = Instance.new("BodyPosition") Woosh.maxForce = Vector3.new(math.huge, math.huge, math.huge) Woosh.position = Vector3.new(Mouse.Hit) Woosh.Parent = Shot end end)
This is meant to fire the "Shot" Part from my torso and to wherever my mouse is pointing, however it fires to the middle of the baseplate and I have no idea why. The output doesn't say anything. Please help.
The problem is you only define the Mouse.Hit
part in the Vector 3 position. After I did some tinkering with the script, I noticed that using (Mouse.Hit.x, Mouse.Hit.y, Mouse.hit.z)
made it go almost exactly where I wanted it to go. The updated code is below.
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 local Shot = Instance.new("Part", workspace) Shot.Name = "RayPart" Shot.BrickColor = BrickColor.new("Bright red") Shot.Transparency = 0 Shot.Anchored = false Shot.CanCollide = false Shot.TopSurface = Enum.SurfaceType.Smooth Shot.BottomSurface = Enum.SurfaceType.Smooth Shot.formFactor = Enum.FormFactor.Custom Shot.Size = Vector3.new(5, 5, 5) Shot.CFrame = Player.Character.Torso.CFrame*CFrame.new(0,0,0) local Woosh = Instance.new("BodyPosition") Woosh.maxForce = Vector3.new(math.huge, math.huge, math.huge) Woosh.position = Vector3.new(Mouse.Hit.x, Mouse.Hit.y, Mouse.Hit.z) Woosh.Parent = Shot end end)