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

My laser projectile script doesn't work why? [BodyVelocity & Touched]

Asked by 7 years ago

It deals damage until the player finally dies. Then the projectile just freezes in the air. Heres the script maybe you can test it and find out it's problem :(

repeat wait() until game.Players.LocalPlayer.Character

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera
local speed = 100

enabled = false

function shootBeam(key)
    if key.KeyCode == Enum.KeyCode.F and enabled == false then
        enabled = true
        print("pew pew!")

local laser = Instance.new("Part", workspace)
        laser.Name = "laserBeam"
        laser.Anchored = false
        laser.CanCollide = false
        laser.Transparency = 0
        laser.FormFactor = Enum.FormFactor.Custom
        laser.Material = Enum.Material.Neon
        laser.BrickColor = BrickColor.new("Lime green")
        laser.Size = Vector3.new(0.5, 0.5, 2)
        laser.CFrame = player.Character.Torso.CFrame *CFrame.new(0, 1.5, -2.5)

        local bodyvelocity = Instance.new("BodyVelocity", laser)
        bodyvelocity.velocity = player.Character.Torso.CFrame.lookVector * speed

        local debounce = false

        laser.Touched:connect(function(hit)
            if hit.Parent:FindFirstChild("Humanoid") ~= nil and debounce == false then
                debounce = true
                hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 15
                wait(2)
                debounce = false
            end
        end)

        game:GetService("Debris"):AddItem(laser, 2)
        wait(1)
        enabled = false
    end
end

game:GetService("UserInputService").InputBegan:connect(shootBeam)


0
This really bugs me cause I've tried everything. It even does that without the Touched event :( Heavening 10 — 7y
0
Huh I guess nobody really knows why Heavening 10 — 7y
0
Try putting the damage script in a separate script that goes into the beam itsself QuantumToast 261 — 7y
0
Oh!!! Copying the damage script and pasting it in the laser beam! Didn't think of that :o Heavening 10 — 7y

Answer this question