A lot of the time, when I test out my code an error pops up, saying "attempt to index nil with '(certain property)'. If you know how to fix this, please respond.
Code:
game.ReplicatedStorage.SkillEvents["Holy Judgement Skill Events"]["Sun Pillar"].OnServerEvent:Connect(function(player, mousePos) local HolyJudge = game.ReplicatedStorage["Holy Judgement Magic Skills"]["Sun Pillar Skill"] local SunPillar = HolyJudge["Sun Pillar"]:Clone() local SunPillarExplode = HolyJudge["Sun Pillar Explosion"]:Clone() local character = player.Character local localplayer = script.Parent local HolyJudgeCircle = game.ReplicatedStorage["Holy Judgement Magic Skills"].HolyJudgeMagicCircle2:Clone() local HolyJudgeAura = game.ReplicatedStorage["Holy Judgement Magic Skills"].HolyJudgeAura:Clone()
--local mouse = game.Players.LocalPlayer:GetMouse() --// \\-- --|Sun Pillar|-- --\\ //-- wait(1) HolyJudgeCircle.Position = character.LeftFoot.Position HolyJudgeAura.Position = character.HumanoidRootPart.Position SunPillar.Position = character.HumanoidRootPart.Position HolyJudgeCircle.Parent = workspace HolyJudgeAura.Parent = workspace SunPillar.Parent = workspace
print("Checkpoint1") local velocity = Instance.new("BodyVelocity", SunPillar) velocity.Velocity = CFrame.new(SunPillar.Position, mousePos).lookVector * 1
print("Checkpoint2")
--// \\-- --|Sun Pillar Explosion|-- --\\ //-- SunPillar.Touched:Connect(function(hit) if hit:IsDescendantOf(character) or hit:FindFirstChild("ParticleEmitter") then return end SunPillarExplode.Position = SunPillar.Position wait(1) HolyJudgeCircle:Destroy() HolyJudgeAura:Destroy() SunPillar:Destroy() SunPillarExplode.Parent = workspace
print("Checkpoint3")
if hit.Parent:FindFirstChild("Humanoid") then
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
wait(0.5)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
wait(0.5)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
wait(0.5)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
wait(0.5)
hit.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
--else --hit.Parent:FindFirstChild("Humanoid"):TakeDamage(-100)
end
print("Checkpoint4")
wait(3)
SunPillarExplode:Destroy()
print("Checkpoint5")
end)
end)
So, nil is when the script can't find anything.
So, say I do game.Workspace.Part3.Name="Part2"
If Part3
doesn't exist, it will return something like:
Attempt to index nil
Hello.
The error: Attempt to index nil means that you are trying to index (access properties or children) an instance.
Here's an example of a brick that kills you:
Part.Touched:Connect(function(otherPart) local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid") humanoid:TakeDamage(humanoid.Health) end)
As you might already know, physically simulated things can touch a part, including other parts.
The error Attempt to index nil with TakeDamage would pop up in this situation.
Now to get to debugging.
You'd check what the error says. It says Attempt to index nil with TakeDamage, so we know that the parent of TakeDamage
is nil/non-existent.
Now, this is a simple fix. Just add an if statement checking if the humanoid is nil. If it is, it will print "No humanoid found.".
Part.Touched:Connect(function(otherPart) local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid") if humanoid then humanoid:TakeDamage(humanoid.Health) else print("No humanoid found.") end end)
I hope this simple answer helped you. Cheers!
game.ReplicatedStorage.SkillEvents["Holy Judgement Skill Events"]["Sun Pillar"].OnServerEvent:Connect(function(player, mousePos) local HolyJudge = game.ReplicatedStorage["Holy Judgement Magic Skills"]["Sun Pillar Skill"] local SunPillar = HolyJudge["Sun Pillar"]:Clone() local SunPillarExplode = HolyJudge["Sun Pillar Explosion"]:Clone() local character = player.Character local localplayer = script.Parent local HolyJudgeCircle = game.ReplicatedStorage["Holy Judgement Magic Skills"].HolyJudgeMagicCircle2 local HolyJudgeAura = game.ReplicatedStorage["Holy Judgement Magic Skills"].HolyJudgeAura
local mouse = game.Players.LocalPlayer::GetMouse() --// \\-- --|Sun Pillar|-- --\\ //-- wait(1) HolyJudgeCircle.Position = character.LeftFoot.Position HolyJudgeAura.Position = character.HumanoidRootPart.Position SunPillar.Position = character.HumanoidRootPart.Position SunPillar.Parent = workspace
@cruelu, it wouldn't let me reply the full thing
you might need to wait for the object, by using WaitForChild:(object name)
Can You Send A Code Example, So I Can Look Further Into Your Problem? If You Have One Ofc.