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

RayCasting and damage dont work :( ?

Asked by 3 years ago

The beam doesn't do any damage, and I'm not sure it's there at all :/ p.s. im use translate

script.Parent.RemoteEvent.OnServerEvent:connect(function(plr,Pos)

    local ray = Ray.new(Stvol.Position,(Pos)*200)
    local hit,position = workspace:FindPartOnRay(ray)

    if hit and hit.Parent:FindFirstChildOfClass("Humanoid") then
        hit.Parent:FindFirstChildOfClass("Humanoid"):TakeDamage(15)
    end

    -----------------
    local beam = Instance.new("Part", game.Workspace)
    beam.BrickColor = BrickColor.new("Bright yellow")
    beam.Material = Enum.Material.Neon
    beam.Transparency = 0
    beam.Anchored = true
    beam.Locked = true
    beam.CanCollide = false

    local distance = (Stvol.CFrame.p - Pos).magnitude
    beam.Size = Vector3.new(.3, .3, distance)
    beam.CFrame = CFrame.new(Stvol.CFrame.p, Pos) * CFrame.new(0, 0, -distance / 2)
    wait()
    beam:Destroy()
    ----------------

end)

1 answer

Log in to vote
0
Answered by
Axenori 124
3 years ago

You don't seem to have a part in your script which damages a player. That is why it does no damage. You need to get the part the ray hits with :FindPartOnRay(), then check the hit's parent or the hit's parent's parent for a humanoid and if there is a humanoid assign it to a variable which you then damage with humanoid:TakeDamage(number)

if you need an example here's my pistol script, at least the main part:

local Present = true
local RS = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
    local tab = {workspace.IgnoreModel}
    local first = true
local Hole
local Part,Position,Normal
script.Parent.BulletEvent.OnServerEvent:Connect(function(Player, FromP, ToP, BulletPos)
if script.Parent.AbleToShoot.Value == true then
    if first == true then
    table.insert(tab, Player.Character)
    first = false
    end
 local RayCast = Ray.new(FromP,(ToP-FromP).unit*500)
 Part,Position,Normal = game.Workspace:FindPartOnRayWithIgnoreList(RayCast,tab,false,true)
 local Dist = (ToP-FromP).magnitude
 if not Dist then Dist = 300 end
local projectile = script.Parent.Bullet.Projectile:Clone()
projectile.Parent = game.Workspace
projectile.CFrame = CFrame.new(BulletPos, ToP)
projectile.Tracer.Enabled = true
 Hole = game.ReplicatedStorage:FindFirstChild("GlockBulletHole"):Clone()
-------------------------------------------------------------------
local Info = TweenInfo.new(
    (ToP-script.Parent.Parts.BE.Position).magnitude/457,
    Enum.EasingStyle.Sine,
    Enum.EasingDirection.Out,
    0,
    false,
    0
)


local Goals  =
{
    Position = ToP
}

local BulletTween = TweenService:Create(projectile, Info, Goals)
BulletTween:Play()

if (ToP-script.Parent.Parts.BE.Position).magnitude <= 1000 then
game.Debris:AddItem(projectile, (ToP-script.Parent.Parts.BE.Position).magnitude/457)
elseif (ToP-script.Parent.Parts.BE.Position).magnitude > 1000 then
game.Debris:AddItem(projectile, 2.2)
end
end
-------------------------------------------------------------------
wait((ToP-script.Parent.Parts.BE.Position).magnitude/457)
if Part ~= nil then
 Hole.Parent = Part
 Hole.Position = Position
 Hole.Material = Part.Material
 Hole.Color = Part.Color
 Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal)
table.insert(tab, Hole)
local breakoffParts = {Instance.new("Part", workspace),Instance.new("Part", workspace),Instance.new("Part", workspace),Instance.new("Part", workspace)}
for i, v in pairs(breakoffParts) do
    v.Position = Hole.Position
    v.Orientation = Vector3.new(math.random(0,360),math.random(0,360),math.random(0,360))
    local mesh = Instance.new("SpecialMesh", v)
    mesh.MeshType = Enum.MeshType.Wedge
    v.Size = Vector3.new(0.05,0.05,0.05)
    v.Material = Part.Material
    v.Color = Part.Color
    v.Transparency = Part.Transparency
    v.Reflectance = Part.Reflectance
    v.Velocity = Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
    table.insert(tab, v)
    game.Debris:AddItem(v, 2)
end

 if Part.Material == Enum.Material.Slate or Part.Material == Enum.Material.Sand or Part.Material == Enum.Material.Pebble or Part.Material == Enum.Material.Brick or Part.Material == Enum.Material.Concrete or Part.Material == Enum.Material.Cobblestone or Part.Material == Enum.Material.Granite or Part.Material == Enum.Material.Marble or Part.Material == Enum.Material.Wood or Part.Material == Enum.Material.WoodPlanks or Part.Material == Enum.Material.Plastic or Part.Material == Enum.Material.SmoothPlastic then
 Hole.Dust.Enabled = true
 end
if Part.Material == Enum.Material.Wood or Part.Material == Enum.Material.WoodPlanks then
    Hole.Splinter.Enabled = true
end

if Part.Material == Enum.Material.Glass then
    if Part.CanCollide == true then
        Part.CanCollide = false
    local BreakSound = script.Parent.Glass:Clone()
    BreakSound.Parent = Part
    BreakSound:Play()
    game.Debris:AddItem(BreakSound, BreakSound.TimeLength)
    Part.CanCollide = false
    if Part:FindFirstChild("Shatter") == nil then
    local eft = script.Parent.Shatter:Clone()
    eft.Parent = Part
    eft.Enabled = true
    eft.Color = ColorSequence.new(Part.Color)
    eft.Transparency = NumberSequence.new(Part.Transparency)
    Hole.H1.Transparency = 1
    Hole.H2.Transparency = 1
    end
            else
        Hole.H1.Transparency = 1
        Hole.H2.Transparency = 1
    end
    end

    if Part.Material == Enum.Material.Slate or Part.Material == Enum.Material.Pebble or Part.Material == Enum.Material.Brick or Part.Material == Enum.Material.Concrete or Part.Material == Enum.Material.Cobblestone or Part.Material == Enum.Material.Granite or Part.Material == Enum.Material.Marble then
        Hole.Rock.Enabled = true
        Hole.Rock.Color = ColorSequence.new(Part.Color)
    end

    if Part.Material == Enum.Material.ForceField then
        Hole.Energy.Enabled = true
            Hole.H1.Transparency = 1
    Hole.H2.Transparency = 1
    end

    if Part.Material == Enum.Material.Plastic or Part.Material == Enum.Material.SmoothPlastic or Part.Material == Enum.Material.Foil then
        Hole.Plastic.Enabled = true
        Hole.Plastic.Color = ColorSequence.new(Part.Color)
    end

    if Part.Material == Enum.Material.Metal or Part.Material == Enum.Material.DiamondPlate or Part.Material == Enum.Material.CorrodedMetal then
 Hole.Sparks.Enabled = true
end

if Part.Material == Enum.Material.Grass then
    Hole.Grass.Enabled = true
            Hole.Grass.Color = ColorSequence.new(Part.Color)
end

    if Part.Material == Enum.Material.Fabric then
    Hole.Fabric.Enabled = true
            Hole.Fabric.Color = ColorSequence.new(Part.Color)
            Hole.TornFabric.Enabled = true
            Hole.TornFabric.Color = ColorSequence.new(Part.Color)
end

Hole.H1.Color3 = Part.Color
Hole.H2.Color3 = Part.Color

 local Weld = Instance.new("Weld")
 Weld.Part0 = Part
 Weld.Part1 = Hole
 Weld.C0 = Part.CFrame:Inverse()
 Weld.C1 = Hole.CFrame:Inverse()
 Weld.Parent = Hole
 if Part and Part.Parent:FindFirstChild("Humanoid") ~= nil then
    for i, v in pairs(breakoffParts) do
        v:Destroy()
    end
    local bleed = script.Parent.Bleeding:Clone()
    bleed.Parent = Part.Parent:FindFirstChild("Humanoid")
    bleed.Value = true
    local damage = 10
    if Part.Name == "Head" then
        damage = math.random(50,70)
        bleed.BleedDamage.Value = 42
    end
        if Part.Name == "Torso" or Part.Name == "HumanoidRootPart" then
            damage = math.random(20,22.5)
            bleed.BleedDamage.Value = 50
        end

        if Part.Parent:IsA("Accessory") then
            if (Part.Position-Part.Parent.Parent.Head.Position).magnitude > (Part.Position-Part.Parent.Parent.Torso.Position).magnitude then
                damage = math.random(20,25)
                bleed.BleedDamage.Value = 50
                elseif (Part.Position-Part.Parent.Parent.Head.Position).magnitude < (Part.Position-Part.Parent.Parent.Torso.Position).magnitude then
                    damage = math.random(50,70)
        bleed.BleedDamage.Value = 42
            end
        end
  Part.Parent.Humanoid:TakeDamage(damage)
    Hole.BloodCloud.Enabled = true
    Hole.Bleed.Enabled = true
    Hole.Blood.Enabled = true
    Hole.Dust.Enabled = false
    Hole.Splinter.Enabled = false
    Hole.Rock.Enabled = false
    Hole.Plastic.Enabled = false
    Hole.Grass.Enabled = false
    Hole.Fabric.Enabled = false
        Hole.H1.Transparency = 1
    Hole.H2.Transparency = 1
    Hole.B1.Transparency = 0.4
    Hole.B2.Transparency = 0.4
else if Part.Parent.Parent:FindFirstChild("Humanoid") and Part ~= nil then
            for i, v in pairs(breakoffParts) do
        v:Destroy()
    end
        local bleed = script.Parent.Bleeding:Clone()
    bleed.Parent = Part.Parent:FindFirstChild("Humanoid")
    bleed.Value = true

    local damage = 10
    if Part.Name == "Head" then
        damage = math.random(50,70)
        bleed.BleedDamage.Value = 42
    end
    if Part.Name == "Torso" or Part.Name == "HumanoidRootPart" then
        damage = math.random(20,25)
        bleed.BleedDamage.Value = 50
    end
          Part.Parent.Parent:FindFirstChild("Humanoid"):TakeDamage(damage)
        Hole.BloodCloud.Enabled = true
        Hole.Bleed.Enabled = true
    Hole.Blood.Enabled = true
    Hole.Dust.Enabled = false
    Hole.Splinter.Enabled = false
    Hole.Rock.Enabled = false
    Hole.Grass.Enabled = false
    Hole.Plastic.Enabled = false
    Hole.Fabric.Enabled = false
    Hole.H1.Transparency = 1
    Hole.H2.Transparency = 1
        Hole.B1.Transparency = 0.4
    Hole.B2.Transparency = 0.4
    end
    end
     Hole.Dust.Color = ColorSequence.new(Part.Color)
end
if Part then
    if Part.Parent ~= nil then
 game.Debris:AddItem(Hole,15)
end
end
end)
0
what the F.... Ugh so hard.. I need time to understand all it tracer_r 19 — 3y
0
I checked my script, and it turned out that I do damage, but only if I aim at myself. I don't know, maybe the beam is stuck somewhere? tracer_r 19 — 3y
0
Is your beam hitting your char? try to print the part which is hit so you know the name Axenori 124 — 3y
0
Is your beam hitting your char? try to print the part which is hit so you know the name Axenori 124 — 3y
Ad

Answer this question