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

How would I create a part where the beam touches another part? [closed]

Asked by 7 years ago

Here's the code, I want to make the "Explosion" part wherever the beam part touches the part it hits. Here's the code:

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

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

    mouse.Button1Down:connect(function()
        print("Mouse 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.Yellow()
        beam.FormFactor = "Custom"
        beam.Material = "Neon"
        beam.Transparency = 0.25
        beam.Anchored = true
        beam.Locked = true
        beam.CanCollide = false



        local distance = (tool.Handle.CFrame.p - position).magnitude
        beam.Size = Vector3.new(.5, .5, distance)
        beam.CFrame = CFrame.new(tool.Handle.CFrame.p, position) * CFrame.new(0, 0, -distance / 2)
        local explosion = Instance.new("Part", workspace)
        explosion.Shape = "Ball"
        explosion.BrickColor = BrickColor.Yellow()
        explosion.Transparency = 0.25
        explosion.Size = Vector3.new(25,25,25)
        explosion.Position = Vector3.new(.5, .5, distance)
        explosion.Anchored = true
        explosion.CanCollide = false
        explosion.Material = "Neon"
        local ex = Instance.new("Explosion")
        ex.Parent = explosion
        ex.Position = Vector3.new(10,10,10)


        game:GetService("Debris"):AddItem(beam, .7)

        if part then
            local humanoid = part.Parent:FindFirstChild("Humanoid")

            if not humanoid then
                humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
            end

            if humanoid then
                humanoid:TakeDamage(30)
            end
            script.Parent.Reload.Disabled = false
            script.Disabled = true

        end
    end)
end)
--script.Parent.Reload.Disabled = false
        --script.Disabled = true

Closed as Not Constructive by Goulstem

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?