fireBall.Touched:Connect(function(Part)
local isRolling = Part.Parent.Humanoid.isRolling
if Part.Name == "Fireball" then
local fireballPos = fireBall.CFrame.Position
fireBall:Destroy()
local explosion = Instance.new("Explosion")
explosion.Parent = workspace
explosion.BlastRadius = 0
explosion.BlastPressure = 0
explosion.Position = fireballPos
local explode = game.SoundService.Fireball.FireballExplode:Clone()
explode.Parent = humanoidRootPart
explode:Play()
end
if Part.Parent:FindFirstChild("Humanoid") and Part.Parent:WaitForChild("Humanoid").Parent ~= character and isRolling.Value == false then
fireBall.CanTouch = false
fireBall:Destroy()
local targetHum = Part.Parent:WaitForChild("Humanoid", 0.5)
local targetChar = Part.Parent
targetHum:TakeDamage(3)
local explode = game.SoundService.Fireball.FireballExplode:Clone()
explode.Parent = humanoidRootPart
explode:Play()
coroutine.wrap(function() -- for ragdolling
wait(0.25)
local r = require(game:GetService("ReplicatedFirst").Ragdoll)
r.RagdollCharacter(targetChar)
print("rag dolled")
local targetVelo = Instance.new('BodyVelocity')
targetVelo.MaxForce = Vector3.new(5000, 5000, 5000)
targetVelo.Velocity = humanoidRootPart.CFrame.LookVector * 30
targetVelo.Parent = targetChar.HumanoidRootPart
task.wait(0.2)
targetVelo:Destroy()
task.wait(0.8)
r.UnRagdollCharacter(targetChar)
end)()
local particleClone = game.ServerStorage.Fireball.ParticleEmitter:Clone() -- for fire proc particles
particleClone.Parent = Part.Parent.HumanoidRootPart
local burningSFX = burning:Clone()
burningSFX.Parent = Part.Parent.HumanoidRootPart
burningSFX:Play()
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
particleClone.Enabled = false
Debris:AddItem(particleClone, 1)
burningSFX:Destroy()
end
wait(4)
fireBall:Destroy()
end)
I want to make it so the player is only damaged once, but since the player has multiple body parts the projectile ends up hitting 7 times. I have looked for solutions on the forum but could not find any, and I’ve tried making it so if the projectile hits a certain part like the players torso they’d take damage, but it still did not work.
Have a boolean outside the touched function.
Something like this:
local sillyNoobGotHit = false
fireBall.Touched:Connect(function(part)
if sillyNoobGotHit == false then
sillyNoobGotHit = true
--damage code here
sillyNoobGotHit = false --only necessary if you don't disconnect the function
end
end)
I did this, and it seemed to lower the number of times the player is hit from 7 to 4. I made the boolean = false in different places to, but the outcome did not change. Is there anything I could be missing?
The debounce/cooldown should wrap the entire function, preventing it from executing until the damage portion has been fully executed. If done correctly then the hits should be 1 time, otherwise it would remain 7 so perhaps your problem lies elsewhere if you’ve fixed this portion of the code
so i put a print statement after the debounce turns to false, and it turns out it goes false everytime the fireball touches ANY object, so perhaps that’s where my problem lies.
local rs = game:GetService("ReplicatedStorage")
local fireBall = rs.FireballCast
local Debris = game:GetService("Debris")
local debounce = false
fireBall.OnServerEvent:Connect(function(Player)
local character = Player.Character
local humanoidRootPart = character.HumanoidRootPart
local FireAnim = character.Humanoid.Animator:LoadAnimation(game.ServerStorage.Animations.FireballCast)
local FireSFX = game.SoundService.Fireball.FireballSFX
local chargeSFX = game.SoundService.Fireball.MagicCharge
local fireExplode = game.SoundService.Fireball.FireballExplode
local burning = game.SoundService.Fireball.Burning
FireAnim:Play()
local charge = game.SoundService.Fireball.MagicCharge:Clone()
charge.Parent = humanoidRootPart
charge:Play()
task.wait(1.1)
local fire = game.SoundService.Fireball.FireballSFX:Clone()
fire.Parent = humanoidRootPart
fire:Play()
local fireBall = game.ServerStorage.Fireball:Clone()
fireBall.Parent = game.Workspace
fireBall:SetNetworkOwner(game:GetService('Players'):GetPlayerFromCharacter(character))
fireBall.CFrame = humanoidRootPart.CFrame * CFrame.new(0, 0, -1)
local bodyVelo = Instance.new('BodyVelocity')
bodyVelo.MaxForce = Vector3.new(10000, 10000, 10000)
bodyVelo.Velocity = humanoidRootPart.CFrame.LookVector * 100
bodyVelo.Parent = fireBall
fireBall.Touched:Connect(function(Part)
if Part.Name == "Fireball" then
local fireballPos = fireBall.CFrame.Position
fireBall:Destroy()
local explosion = Instance.new("Explosion")
explosion.Parent = workspace
explosion.BlastRadius = 0
explosion.BlastPressure = 0
explosion.Position = fireballPos
local explode = game.SoundService.Fireball.FireballExplode:Clone()
explode.Parent = humanoidRootPart
explode:Play()
end
if debounce == false then
debounce = true
local isRolling = Part.Parent.Humanoid.isRolling
if Part.Parent:FindFirstChild("Humanoid") and Part.Parent:WaitForChild("Humanoid").Parent ~= character and isRolling.Value == false then
fireBall.CanTouch = false
fireBall:Destroy()
local targetHum = Part.Parent:WaitForChild("Humanoid", 0.5)
local targetChar = Part.Parent
targetHum:TakeDamage(3)
local explode = game.SoundService.Fireball.FireballExplode:Clone()
explode.Parent = humanoidRootPart
explode:Play()
coroutine.wrap(function() -- for ragdolling
wait(0.25)
local r = require(game:GetService("ReplicatedFirst").Ragdoll)
r.RagdollCharacter(targetChar)
print("rag dolled")
local targetVelo = Instance.new('BodyVelocity')
targetVelo.MaxForce = Vector3.new(5000, 5000, 5000)
targetVelo.Velocity = humanoidRootPart.CFrame.LookVector * 30
targetVelo.Parent = targetChar.HumanoidRootPart
task.wait(0.2)
targetVelo:Destroy()
task.wait(0.8)
r.UnRagdollCharacter(targetChar)
end)()
local particleClone = game.ServerStorage.Fireball.ParticleEmitter:Clone() -- for fire proc particles
particleClone.Parent = Part.Parent.HumanoidRootPart
local burningSFX = burning:Clone()
burningSFX.Parent = Part.Parent.HumanoidRootPart
burningSFX:Play()
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
task.wait(1)
targetHum:TakeDamage(0.5)
particleClone.Enabled = false
Debris:AddItem(particleClone, 1)
burningSFX:Destroy()
end
wait(4)
fireBall:Destroy()
end
debounce = false
print("debo false")
end)
end)
I’ve checked this before, and the 59th line is why the touched function keeps going off, any idea on how to check if the part is player, THEN to check if the said player has “isRolling” in their humanoid?? I tried earlier and I had no idea where to start