Making a "Fireball" do damage when it hits an enemy or player?!
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
01 | local Plr = game:GetService( "Players" ).LocalPlayer |
02 | local tool = script.Parent |
03 | local FireBallAttack = game.ReplicatedStorage:WaitForChild( "FireBallCollisions" ) |
06 | tool.Activated:connect( function (Player) |
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 |
16 | FireBall.CFrame = Plr.Character.HumanoidRootPart.CFrame * CFrame.new( 0 , 0 ,- 6 ) |
17 | local BodyVelocity = Instance.new( "BodyVelocity" ) |
18 | BodyVelocity.Velocity = Plr.Character.HumanoidRootPart.CFrame.LookVector * 90 |
19 | BodyVelocity.MaxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
20 | BodyVelocity.Parent = FireBall |
21 | local Explosion = Instance.new( "Explosion" ) |
23 | FireBall.Touched:Connect( function (hit) |
27 | FireBall.Parent = workspace |
29 | game:GetService( "Debris" ):AddItem(FireBall, 10 ) |
31 | local ClonedFireBallAttck = FireBallAttack:Clone() |
32 | ClonedFireBallAttck.Parent = FireBall |
38 | script.Parent:Destroy() |
And now here's the script in Replicated Storage
2 | if script.Parent.hit:FindFirstChild( "Humanoid" ) then |
3 | local Humanoid = script.Parent.hit:FindFirstChild( "Humanoid" ) |
4 | Humanoid.Health = Humanoid.Health - 20 |
8 | script.Parent.Touched:Connect(OnTouch() |