Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why wont this Body Position script work?

Asked by
neoG457 315 Moderation Voter
8 years ago
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.

1 answer

Log in to vote
1
Answered by 8 years ago

The problem is you only define the Mouse.Hitpart 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) 

Ad

Answer this question