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

How would I fix this script for the guns I am developing?

Asked by 7 years ago
Edited 7 years ago

I made this script for some guns I'm working on, and I cannot seem to get the guns to shoot, I'm not sure what I am doing wrong, any of you able to help? This is what I have so far.

local tool = script.Parent
local player = game:GetService("Players").LocalPlayer

tool.Equipped:connect(function(mouse)
    print("Tool is equipped")

    mouse.Button1Down:connect(function()
        print("Mouse has been pressed")
        local ray = Ray.new(tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * 300)
        local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)

        local beam = Instance.new("Part", workspace)
        beam.BrickColor = BrickColor.new("Crimson")
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false

        local distance = (tool.Handle.CFrame.p - position).magnitude
        beam.Size = Vector3.new(0.3, 0.3, distance)
        beam.CFrame = CFrame.new(tool.Firepiece.CFrame.p, position) * CFrame.new(0,0, -distance / 2)

        game:GetService("Debris"):AddItem(beam, 0.1)

local humanoid =  hit.Parent:FindFirstChild("Humanoid")
                if humanoid then
                    if hit.Name == "Head" then
                        --Double damage on headshots
                        humanoid:TakeDamage(50*2)
                    else
                        --Normal Damage on body shots
                        humanoid:TakeDamage(50)     


    end)
end)

Answer this question