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

How to make a raycast do damage in FE? [closed]

Asked by 6 years ago
Edited 6 years ago

Someone asked this question but it got taken down so I'm going to ask (and answer it) for him Hope this can help anyone reading this question.

Closed as Not Constructive by valchip and User#19524

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?

1 answer

Log in to vote
-6
Answered by 6 years ago
Edited 6 years ago

First create a RemoteEvent in your gun and name it FireEvent

Second create a normal script (not a local script) in your gun

Third change your local script to this

mouse.Button1Down:connect(function()
    local ray = Ray.new(hole.CFrame.p, (mouse.Hit.p - hole.CFrame.p).unit * 300)
    local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
    script.Parent:WaitForChild("FireEvent"):FireServer(part, position)
end)

Finally copy and paste this into your normal script

script.Parent:WaitForChild("FireEvent").OnServerEvent:connect(function(player, part, position)
    local beam = Instance.new("Part", game.Workspace)
    beam.BrickColor = BrickColor.new("Bright red")
    beam.FormFactor = "Custom"
    beam.Material = "Neon"
    beam.Transparency = 0.5
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false

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

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

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

        if humanoid then
            print("hit "..part.Name)
            local damage = 25
        humanoid:TakeDamage(damage)
        end
    end
end)
Ad