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

How can I modify this gun script so that It shoots bullets where your mouse Is?

Asked by 1 year ago

Hello Developers!

As the title states, I want to modify the script below to shoot bullets where your mouse Is at

local Tool = script.Parent


Tool.RemoteEvent.OnServerEvent:Connect(function()
    local Ball = Instance.new("Part",game.Workspace)
    local CanDamage = true
    game:GetService("Debris"):AddItem(Ball,3)
    Ball.Position = Tool.Handle.Position
    Ball.Orientation = Tool.Parent.Torso.Orientation
    Ball.Size = Vector3.new(1.02, 1.02, 1.02)
    Ball.CastShadow = false
    Ball.Anchored = false
    Ball.Material = Enum.Material.Grass
    Ball.Shape = Enum.PartType.Ball
    Tool.Handle.Fire:Play()
    Tool.Handle.Attachment.Fire.Enabled = true
    Tool.Handle.Attachment.PointLight.Enabled = true
    Ball.Touched:Connect(function(hit)
        local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if Player then
            local player1 = game.Players:GetPlayerFromCharacter(hit.Parent)
            local player2 = game.Players:GetPlayerFromCharacter(Tool.Parent)

            if (player1 ~= nil) and (player2 ~= nil) then
                local humanoid = (player1.Character or player1.CharacterAdded:Wait()):FindFirstChildWhichIsA("Humanoid")

                if (player1.TeamColor ~= player2.TeamColor) then
                    if (humanoid ~= nil) and CanDamage == true then
                        humanoid:TakeDamage(15)
                        CanDamage = false
                    end
                end
            end
        elseif not Player then
            local humanoid = hit.Parent:WaitForChild("Humanoid")
            if humanoid and CanDamage == true then
                humanoid:TakeDamage(15)
                CanDamage = false
            end
        end
    end)
    local KnockBack = Instance.new("VectorForce")
    local Attachment = Instance.new("Attachment")

    KnockBack.Parent = Ball
    Attachment.Parent = Ball
    KnockBack.Attachment0 = Attachment
    KnockBack.ApplyAtCenterOfMass = true
    KnockBack.Force =  Vector3.new(0,300,-6000)
    game:GetService("Debris"):AddItem(KnockBack,.05)
    game:GetService("Debris"):AddItem(Attachment,.05)
    wait(0.1)
    Tool.Handle.Attachment.Fire.Enabled = false
    Tool.Handle.Attachment.PointLight.Enabled = false
end)

1 answer

Log in to vote
0
Answered by
Puppynniko 1059 Moderation Voter
1 year ago

Give the mouse position in the client and move the bullet to that location

0
How can I do that? imnotaguest1121 362 — 1y
0
do you have discord? because it would be pretty annoying to text back and back hours of interval my user is eeeee#6221 Puppynniko 1059 — 1y
0
you might also consider watching a how to make gun vid it have the things you need Puppynniko 1059 — 1y
Ad

Answer this question