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 5 years ago
Edited 5 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

01local Plr = game:GetService("Players").LocalPlayer
02local tool = script.Parent
03local FireBallAttack = game.ReplicatedStorage:WaitForChild("FireBallCollisions")
04local Ammo = 5
05 
06    tool.Activated:connect(function(Player)
07 
08    local FireBall = Instance.new("Part")
09    FireBall.Shape = "Ball"
10    FireBall.BrickColor = BrickColor.new("Maroon")
11    FireBall.Transparency = 0.5
12    FireBall.TopSurface = "Smooth"
13    FireBall.BottomSurface = "Smooth"
14    local Fire = Instance.new("Fire")
15    Fire.Parent = FireBall
View all 37 lines...

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

1function OnTouch(hit)
2    if hit.Parent.hit:FindFirstChild("Humanoid") then
3        hit.Parent.Humanoid:TakeDamage(20)
4    script.Parent.CanCollide = false
5script.Parent:Destroy()
6    end
7end
8 
9script.Parent.Touched(OnTouch)

If you can answer this then thx.

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

2 answers

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

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

1script.Parent.Touched:Connect(function(hit)
2     local humanoid= hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid")
3    if humanoid then
4            humanoid:TakeDamage(20)
5        script.Parent.CanCollide = false
6        script.Parent:Destroy()
7        end
8end)

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 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

01function onTouched(hit)
02    local human = hit:FindFirstAncestorOfClass("Model"):FindFirstChild("Humanoid")
03    if human ~= nil and debounce == true then
04        debounce = false
05        human:TakeDamage(AMOUNT OF DAMAGE)
06        print("Hit somebody!")
07        script.Parent:Destroy()
08    end
09 
10    debounce = true
11 
12end
13 
14-- Making sure the brick is still in existence before processing the touch.
15if script.Parent ~= nil then
16    debounce = true
17    local connection = script.Parent.Touched:connect(onTouched)
18end

Answer this question