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

I still can't make a fire ball do damage?!

Asked by 4 years ago
Edited 4 years ago

I've asked this question before and I did what those kind people told me but, it still didn't work. I have 2 scripts to make a quote on quote "FireBall" when shot out from and tool and hits an enemy with a Humanoid it does damage to it. The first script is in the tool.

Here's the first one

local Plr = game:GetService("Players").LocalPlayer
local tool = script.Parent
local FireBallAttack = game.ReplicatedStorage:WaitForChild("FireBallCollisions")
local Ammo = 5

    tool.Activated:connect(function(Player)

    local FireBall = Instance.new("Part")
    FireBall.Shape = "Ball"
    FireBall.BrickColor = BrickColor.new("Maroon")
    FireBall.Transparency = 0.5
    FireBall.TopSurface = "Smooth"
    FireBall.BottomSurface = "Smooth"
    local Fire = Instance.new("Fire")
    Fire.Parent = FireBall
    FireBall.CFrame = Plr.Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-6)    
    local BodyVelocity = Instance.new("BodyVelocity")
    BodyVelocity.Velocity = Plr.Character.HumanoidRootPart.CFrame.LookVector * 90
    BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
    BodyVelocity.Parent = FireBall
    local Explosion = Instance.new("Explosion")
    FireBall.Parent = workspace
    --Add Fireball to debris (will be destroyed after 60 seconds)
    game:GetService("Debris"):AddItem(FireBall,10)

local ClonedFireBallAttck = FireBallAttack:Clone()
ClonedFireBallAttck.Parent = FireBall

    Ammo = Ammo - 1 

print(Ammo)
if Ammo == 0 then 
    script.Parent:Destroy()
end


end)

And now here's the 2nd script in replicated storage

function OnTouch(hit)
    if hit.Parent.hit:FindFirstChild("Humanoid") then
        hit.Parent.Humanoid:TakeDamage(20)
    script.Parent.CanCollide = false
script.Parent:Destroy()
    end
end

script.Parent.Touched(OnTouch)

If you can answer this then thx.

0
Is the damage script disabled when cloned to the part? Despayr 505 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

"hit.Parent.hit" is not correct. I would write it like this:

script.Parent.Touched:Connect(function(hit)
     local humanoid= hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
    if humanoid then
            humanoid:TakeDamage(20)
        script.Parent.CanCollide = false
        script.Parent:Destroy()
        end
end)

In this you would test if the part you hit has a humanoid in it's parent or if the parent of the parent of the part you hit has a humanoid.

0
I'd recommend using 'FindFirstChildOfClass("Humanoid")' instead Despayr 505 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Assuming everything else works, here is an easy script I have been using to take damage.

function onTouched(hit)
    local human = hit:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid") 
    if human ~= nil and debounce == true then
        debounce = false
        human:TakeDamage(AMOUNT OF DAMAGE)
        print("Hit somebody!")
        script.Parent:Destroy()
    end

    debounce = true

end

-- Making sure the brick is still in existence before processing the touch.
if script.Parent ~= nil then
    debounce = true
    local connection = script.Parent.Touched:connect(onTouched)
end

Answer this question