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 4 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

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()
0
In the Fireball script, pass the function only: script.Parent.Touched:Connect(OnTouch) SaltyIceberg 81 — 4y
0
bro capitalize the c in connect its deprecated, this might even be the whole problem because the function doesnt begin AltNature 169 — 4y

2 answers

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

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)

Answer this question