Attempt to index nil with "Position" [SOLVED]

The code I did for the bomb work but it get this annoying error,
Plus I already tried CFrame and it gives the same message but with “CFrame”

I wanted it to when touched the part explodes, and removes the minibomb(“The throwing part”)
image

I already tried everything I know, and it doesnt work

heres the code

local BombFolder = game.ReplicatedStorage:WaitForChild("Bomb")
local Remote2 = BombFolder.Remote.BombThrow
local Debris = game:GetService("Debris")
local Animation = BombFolder.Animations.BombThrow
local Damage = 20

local ExplosionSound = BombFolder.Sounds.Explosion

local TweenService = game:GetService("TweenService")




local Informatic = TweenInfo.new(
	0.75,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
    0,
	false,
	0
)

local Propreties = {Size = Vector3.new(5.649, 5.649, 5.649)}



Remote2.OnServerEvent:Connect(function(plr)
	local RedExplosion = BombFolder.Meshes.RedExplosion:Clone()
	local Character = plr.Character or plr.CharacterAdded:Wait()
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
	local Humanoid = Character:FindFirstChild("Humanoid")
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
	
	
	local RedExplosionDescendents = {
		 A0 = BombFolder.Meshes.RedExplosion.A:Clone(),
		A1 = BombFolder.Meshes.RedExplosion.A1:Clone(),
		A2 = BombFolder.Meshes.RedExplosion.A2:Clone(),
		A3 = BombFolder.Meshes.RedExplosion.A3:Clone(),
	}
	
	
	local MiniBomb = BombFolder.Meshes.MiniBomb:clone()
	local TweenTrack1 = TweenService:Create(RedExplosionDescendents.A0,Informatic,Propreties)
	local TweenTrack2 = TweenService:Create(RedExplosionDescendents.A1,Informatic,Propreties)
	local TweenTrack3 = TweenService:Create(RedExplosionDescendents.A2,Informatic,Propreties)
	local TweenTrack4 = TweenService:Create(RedExplosionDescendents.A3,Informatic,Propreties)
	
	
	
	MiniBomb.Parent = workspace
	MiniBomb.CFrame = HumanoidRootPart.CFrame
	
	local BodyV = Instance.new("BodyVelocity", MiniBomb)
	BodyV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	BodyV.Velocity = HumanoidRootPart.CFrame.LookVector * 100
	
	MiniBomb.Touched:Connect(function(hit)
		if hit.Parent == plr.Character then return end

		if hit.Parent:FindFirstChild("Humanoid") then
			task.wait(0.5)
			hit.Parent:FindFirstChild("Humanoid"):TakeDamage(Damage)
			RedExplosionDescendents.Parent = workspace
			Debris:AddItem(RedExplosionDescendents.AO,1)
			Debris:AddItem(RedExplosionDescendents.A1,1)
			Debris:AddItem(RedExplosionDescendents.A2,1)
			Debris:AddItem(RedExplosionDescendents.A3,1)
			RedExplosionDescendents.A0.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position
			RedExplosionDescendents.A1.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position
			RedExplosionDescendents.A2.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position
			RedExplosionDescendents.A3.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position
			TweenTrack1:Play()
			TweenTrack2:Play()
			TweenTrack3:Play()
			TweenTrack4:Play()
			ExplosionSound:play()
			MiniBomb:Destroy()
		end
	end)
	
end)

Thanks for your time.

1 Like

Try this…

local BombFolder = game.ReplicatedStorage:WaitForChild("Bomb")
local Remote2 = BombFolder.Remote.BombThrow
local Debris = game:GetService("Debris")
local Animation = BombFolder.Animations.BombThrow
local Damage = 20

local ExplosionSound = BombFolder.Sounds.Explosion

local TweenService = game:GetService("TweenService")




local Informatic = TweenInfo.new(
	0.75,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local Propreties = {Size = Vector3.new(5.649, 5.649, 5.649)}



Remote2.OnServerEvent:Connect(function(plr)
	local RedExplosion = BombFolder.Meshes.RedExplosion:Clone()
	local Character = plr.Character or plr.CharacterAdded:Wait()
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
	local Humanoid = Character:FindFirstChild("Humanoid")
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()


	local RedExplosionDescendents = {
		A0 = BombFolder.Meshes.RedExplosion.A:Clone(),
		A1 = BombFolder.Meshes.RedExplosion.A1:Clone(),
		A2 = BombFolder.Meshes.RedExplosion.A2:Clone(),
		A3 = BombFolder.Meshes.RedExplosion.A3:Clone(),
	}


	local MiniBomb = BombFolder.Meshes.MiniBomb:clone()
	local TweenTrack1 = TweenService:Create(RedExplosionDescendents.A0,Informatic,Propreties)
	local TweenTrack2 = TweenService:Create(RedExplosionDescendents.A1,Informatic,Propreties)
	local TweenTrack3 = TweenService:Create(RedExplosionDescendents.A2,Informatic,Propreties)
	local TweenTrack4 = TweenService:Create(RedExplosionDescendents.A3,Informatic,Propreties)



	MiniBomb.Parent = workspace
	MiniBomb.CFrame = HumanoidRootPart.CFrame

	local BodyV = Instance.new("BodyVelocity", MiniBomb)
	BodyV.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
	BodyV.Velocity = HumanoidRootPart.CFrame.LookVector * 100
	local debounce = false
	MiniBomb.Touched:Connect(function(hit)
		if hit.Parent == plr.Character then return end
		if not debounce then
			debounce = true
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") then
				task.wait(0.5)
				hit.Parent.Humanoid:TakeDamage(Damage)
				RedExplosionDescendents.Parent = workspace
				Debris:AddItem(RedExplosionDescendents.AO,1)
				Debris:AddItem(RedExplosionDescendents.A1,1)
				Debris:AddItem(RedExplosionDescendents.A2,1)
				Debris:AddItem(RedExplosionDescendents.A3,1)
				RedExplosionDescendents.A0.Position = hit.Parent.HumanoidRootPart.Position
				RedExplosionDescendents.A1.Position = hit.Parent.HumanoidRootPart.Position
				RedExplosionDescendents.A2.Position = hit.Parent.HumanoidRootPart.Position
				RedExplosionDescendents.A3.Position = hit.Parent.HumanoidRootPart.Position
				TweenTrack1:Play()
				TweenTrack2:Play()
				TweenTrack3:Play()
				TweenTrack4:Play()
				ExplosionSound:play()
				MiniBomb:Destroy()
			end
			debounce = false
		end

	end)

end)

I added a debounce so that the script doesn’t over fire (if it over fires it could cause issues like killing the player because it’s applied over 200 more times than expected, and the player being removed while this is processing could cause the parts to disappear unexpectedly) and i added another condition to your if statement

1 Like

Hey there,

The minibomb gets throwed out but it doesnt do damage and neither gets exploded like intended. No errors

Thanks tho

That’d likely be because there was neither a humanoid or a humanoidrootpart found on anything that was touched, do you have a video example that you can provide?

An alternative you could change these lines to get some more information


debounce = true
			if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") then

Change with

debounce = true
print("----------New Touch process---------------"
print(hit.Name)
print(hit.Parent.Name)
print(hit.Parent:FindFirstChild("HumanoidRootPart"))
		if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") then

with that it’ll output a bit of information, but it’ll tell you what it hit, and if it had a root part.

The hit.Name output could assist with determining why this isn’t processing as intended.

1 Like

Thats what prints, My pc is too laggy to provide videos but sure I’ll try.

I’ll change the dummy’s
if thats the problem

Could you show me line 70 and what you the assignment of what you tried to index?

1 Like

Now It’s dealing damage, but not showing the explosion effect.

https://gyazo.com/8a309bb6847d3d0600c0be1bc7b2712e

Here’s the video

RedExplosionDescendents.A0.Position = hit.Parent:FindFirstChild("HumanoidRootPart").Position

I tried making the explosion effects position/CFrame equal to player’s that got hit humanoidrootpart

It’s not giving me the error anymore, but the explosion still doesnt go to workspace and do the “blow up” effect.

Test the game and take a look at the explorer when you cause damage. Maybe it’s something with the properties.

1 Like

on line 36 you made a table which has clones of the RedExplosion, and on like 68 you try to parent the table to workspace, does this work? Do you see those objects appear in the workspace explorer now that the damage is processing? If not then you may need to adjust how you’re getting that explosion effect in place. (I’ve not seen it done like this before, if it does work that’d be cool to know!)

1 Like

So see if the effect parents workspace or if it’s a different property.

1 Like

After correcting the things you guys said its finnaly working, thank you so much!

And plus @SnazpantsMixer, its not possible to make the entire table parent to workspace without specifying the part

1 Like