Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make a raycast do damage in FE?

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.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.