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

Making a "Fireball" do damage when it hits an enemy or player?!

Asked by 5 years ago

I'm making a script where you launch a "Fireball" from a tool. But, what I want the "Fireball" to do damage to enemy monsters or players. I'm sending a script in Repliacted Storage and cloning that script into the fireball and using the On Touch command to make the fire ball do damage.

Here is the script in the tool

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 42 lines...

And now here's the script in Replicated Storage

1function OnTouch(hit)
2    if script.Parent.hit:FindFirstChild("Humanoid") then
3        local Humanoid = script.Parent.hit:FindFirstChild("Humanoid")
4        Humanoid.Health = Humanoid.Health - 20
5    end
6end
7 
8script.Parent.Touched:Connect(OnTouch()
0
In the Fireball script, pass the function only: script.Parent.Touched:Connect(OnTouch) SaltyIceberg 81 — 5y
0
bro capitalize the c in connect its deprecated, this might even be the whole problem because the function doesnt begin AltNature 169 — 5y

2 answers

Log in to vote
0
Answered by
iXBruv 24
5 years ago

It should be if hit.Parent:FindFirstChild("Humanoid"), and you should also use hit.Parent.Humanoid:TakeDamage(20) instead of subtracting health, although they are pretty much the same ig

0
Also you may be connecting OnTouch wrong iXBruv 24 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

One thing is that instead of doing-

1Humanoid.Health = Humanoid.Health - 20

You can write-

1Humanoid:TakeDamage(20)

and like iXBruv said, I think you might wanna make (OnTouch() be (OnTouch)

Answer this question