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

Why does my bullet script act weird when the target is a part?

Asked by
Viking359 161
5 years ago
Edited 5 years ago

I've recently started making a gun script and everything seems to be working fine, but whenever I click on something that isn't the empty void, the bullet goes in a slightly different direction.

local re = script.Parent.RE

re.OnServerEvent:Connect(function(player, mouse)
    local h = mouse.Hit
    local p = h.p
    local s = script.Parent.Barrel.Position

    local b = Instance.new("Part", workspace)
    b.Size = Vector3.new(.25,.25,.25)
    b.Transparency = 1
    b.Position = s
    b.CanCollide = false

    local t = Instance.new("Trail", b)
    t.FaceCamera = true
    t.Lifetime = .75
    t.MinLength = .15   
    t.LightEmission = 0.25

    local aa = Instance.new("Attachment", b)
    aa.Position = Vector3.new(0.35, 0, 0)
    aa.Name = "Attachment1"
    local ab = Instance.new("Attachment", b)
    ab.Position = Vector3.new(-0.35, 0, 0)
    ab.Name = "Attachment1"

    t.Attachment0 = aa
    t.Attachment1 = ab

    local bv = Instance.new("BodyVelocity", b)
    bv.MaxForce = Vector3.new(9e9, 9e9, 9e9)
    bv.Velocity = (p*100)

    wait(3)
    if b then
        b:Destroy()
    end
end)

This is my first time making a gun, so any help is appreciated!

0
You can’t get the Mouse on the server. User#19524 175 — 5y
0
You can get the Mouse.Hit by passing it as a parameter on the server, but can’t pass the mouse object itself. User#19524 175 — 5y
0
I moved the GetMouse() to the local script Viking359 161 — 5y
0
No no no, you passed the mouse as a parameter. Remove it. User#19524 175 — 5y
View all comments (2 more)
0
What do I remove and what do I put instead? Viking359 161 — 5y
0
Remove the mouse parameter, and put the mouse’s Hit as a parameter instead, and when you FireServer the remote, include the hit as an argument User#19524 175 — 5y

Answer this question