So i was making a fire ball which explodes upon contact with any objects that can be collided. After colliding, the fireball blows up into a sphere (Sphere grows from small to big). When the aoe explosion touches any humanoid character, my script will grab an IntValue from the lighting and put it into the target (To serve as a multi hit debounce).
Everything was working fine except when i tried to change the value of the IntValue. The first time upon touching, it grabs the IntValue from lighting and placed it inside the character model just fine, but when the code tries to change its value from the character, this error appeared: "attempt to index local 'aoecheck' (a nil value)".
After this error appeared, I tried to hit myself with the explosion aoe again but this time onward, everything worked as intended. If i were to grab that IntValue from the lighting before hitting myself with the aoe blast, it will also work. Any ideas?
localscript (No error)
--declaring shortcuts
fireball = script.Parent
player = game.Players.LocalPlayer
remote = fireball.RemoteEvent
mouse = player:GetMouse()
clickdebounce = false
fireball.Activated:connect(function()
if clickdebounce == false then
clickdebounce = true
fireball.RemoteEvent:FireServer()
wait(0.5)
clickdebounce = false
end
end)
script (The one with the error: Line 47)
--declaring shortcuts
fireball = script.Parent
remote = fireball.RemoteEvent
player = fireball.Parent.Parent
character = player.Character
mouse = player:GetMouse()
dmgdebounce = false
aoedebounce = false
testvalue = 0
remote.OnServerEvent:connect(function()
local projectile = fireball.Handle:Clone()
local bv = Instance.new("BodyVelocity",projectile)
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Velocity = mouse.hit.lookVector * 50
projectile.Parent = game.Workspace
projectile.Touched:connect(function(entity)
local humanoid = entity.Parent:FindFirstChild("Humanoid")
if not entity:IsDescendantOf(character) and entity.CanCollide == true then
--FireBall Damage--
if humanoid then
humanoid:TakeDamage(10)
print("took fireball damage")
end
--creating an aoe
local aoe = game.Lighting.AOE:Clone()
aoe.Parent = workspace
aoe.CFrame = projectile.CFrame
projectile:Destroy()
--AOE Damage--
for i = 0,10 do
aoe.Touched:connect(function(aoentity)
local aoecounter = game.Lighting.AoeDebounce:Clone()
local aoehumanoid = aoentity.Parent:FindFirstChild("Humanoid")
local aoecheck = aoentity.Parent:FindFirstChild("AoeDebounce")
if not aoecheck then
aoecounter.Parent = aoentity.Parent
end
if aoehumanoid and aoedebounce ==false and aoehumanoid.Health>0 then
aoecheck.Value = aoecheck.Value +1 --ERROR HERE
aoehumanoid:TakeDamage(10)
print("took aoe dmg")
end
end)
aoe.Size = Vector3.new(i*5,i*5,i*5)
wait(0.05)
end
aoedebounce = false
aoe:Destroy()
end
end)
end)
The desired goal was increasing the distributed "AoeDebounce" inside the target character by 1 every time the aoe blast touches them, without the error popping up.
Required stuff for the code:
1)Tool inside StarterPack
2)Handle inside tool
3)RemoteEvent inside tool
4)LocalScript inside tool
5)Script inside tool
Sphere part named "AOE" inside Lighting (Remember to anchor it and set Cancollide = false)
IntValue named "AoeDebounce" inside lighting

4 comments
try tracking it down, so look at Aoecheck, that is previously seen in line forty, where you mention aoenity, track that down, you use that as a parameter in line 37. Keep moving down the line till you find the problem, examine each line carefully.
That seems to be the problem thanks. I just changed lined 47's "aoecheck.Value = aoecheck.Value +1" into "aoentity.Parent.AoeDebounce.Value = aoentity.Parent.AoeDebounce.Value +1". But I still don't understand why can't i use my first statement insead. I thought I've already declared that "aoecheck = aoentity.Parent:FindFirstChild("AoeDebounce")" don't they mean the same thing?
Also, with my first statement why does it work only after i hit myself the second time the aoe?
I'm sorry I don't know