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
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") --create touched event FireBall.Touched:Connect(function(hit) wait() FireBall:Destroy() end) 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 script in Replicated Storage
function OnTouch(hit) if script.Parent.hit:FindFirstChild("Humanoid") then local Humanoid = script.Parent.hit:FindFirstChild("Humanoid") Humanoid.Health = Humanoid.Health - 20 end end script.Parent.Touched:Connect(OnTouch()
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
One thing is that instead of doing-
Humanoid.Health = Humanoid.Health - 20
You can write-
Humanoid:TakeDamage(20)
and like iXBruv said, I think you might wanna make (OnTouch() be (OnTouch)