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()

2 comments
In the Fireball script, pass the function only: script.Parent.Touched:Connect(OnTouch)
bro capitalize the c in connect its deprecated, this might even be the whole problem because the function doesnt begin