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

Why are the bullets in my gun not moving? The body velocity is in the bullet and it isn't anchored.

Asked by
Master_JJ 229 Moderation Voter
7 years ago

I just want to say that I made sure the part is unanchored.

I used remote events, so there are two scripts.

Server Script:

local tool = script.Parent
local event = tool.ClickEvent
local handle = tool.Handle

function createPart()
    local part = Instance.new("Part")
    part.Parent = workspace
    part.Size = Vector3.new(.2, .2, .2)
    part.BrickColor = BrickColor.Yellow()
    part.Anchored = false
    part.CanCollide = false
    return part
end

event.OnServerEvent:connect(function(player, mouseLocation)
    local part = createPart()
    part.CFrame = tool.Handle.CFrame
    part.CFrame = CFrame.new(part.Position, mouseLocation)
    local bodyVelocity = Instance.new("BodyVelocity", part)
    bodyVelocity.velocity = part.CFrame.lookVector * 90
    bodyVelocity.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    game.Debris:AddItem(part, 15)
end)

Local Script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local tool = script.Parent
local event = tool.ClickEvent


tool.Activated:connect(function()
    local mouseLocation = mouse.Hit.p
    event:FireServer(mouseLocation)
end)
0
Just a thought: might the bullet be automatically creating welds with other objects when you put it into the workspace? If that is happening, the solution would be to call :BreakJoints on the bullet (after line 18). chess123mate 5873 — 7y

Answer this question