Keep getting error

wait(4)
local rp = game:WaitForChild("ReplicatedStorage")
local bh1 = rp:WaitForChild("Run")
local TweenSer = game:GetService("TweenService")
local PsycSer = game:GetService("PhysicsService")
PsycSer:CreateCollisionGroup("Clone")
PsycSer:CreateCollisionGroup("Player")
PsycSer:CollisionGroupSetCollidable("Clone","Player",false)
local Sound = script.Lighting
Sound.Parent = workspace
local Sound2 = script.Lighting2
Sound2.Parent = workspace
local Dust = script.Dust
Dust.Parent = workspace
local InAir = false

bh1.OnServerEvent:Connect(function(player,Target)
	
	local chr = player.Character
	local randomCF = math.random(0,8)
	local ArmAnim = chr.Humanoid:LoadAnimation(script.LightAnim)	
if Target and Target.Parent:FindFirstChild("MouseHitBox") and InAir == false or Target.Parent:FindFirstChild("Humanoid") and InAir == false  then
		local ServerStore = game:GetService("ServerStorage")
		local TweenSer = game:GetService("TweenService")
		local LightMod = require(game.ServerStorage.LightingScript)
		local SmallMod = require(game.ServerStorage.SmallLightingScript)
		ArmAnim:Play()
		spawn(function()
			for i = 1,4 do
				local StartPart = script.StartPart:Clone()
				StartPart.Parent = workspace
				StartPart.CFrame = Target.Parent:FindFirstChild("MouseHitBox").Parent.HumanoidRootPart.CFrame * CFrame.new(math.random(-2,2),math.random(-2,2),math.random(-2,2))
				
				local EndPart = script.EndPart:Clone()
				EndPart.Parent = workspace
				EndPart.CFrame = StartPart.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1))
				
				local Mod = SmallMod.MakeLight(StartPart.Position, EndPart.Position,4)
				wait(0.15)
				for _,Parts in pairs(Mod:GetChildren()) do
					TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Size = Vector3.new(0,0,0)}):Play()
					TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Transparency = 1}):Play()
				end
				game.Debris:AddItem(Mod,0.2)
				game.Debris:AddItem(StartPart,0.2)
				game.Debris:AddItem(EndPart,0.2)
			end
		end)
	
		workspace.Start.CFrame = Target.Parent:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0,math.random(100,150),0)
		workspace.End.CFrame = Target.Parent:FindFirstChild("HumanoidRootPart").CFrame 
		
		local LightEfxMod = require(game.ServerStorage.LightningDownVfx)
		LightEfxMod.LightDownFunction(workspace.Start)
		spawn(function()
		for i = 1,10 do	
				wait()
				local StartPart = script.StartPart:Clone()
				StartPart.Parent = workspace
				StartPart.CFrame = workspace.Start.CFrame * CFrame.new(math.random(-4,8),math.random(4,6),math.random(-4,8))

				local EndPart = game.Workspace.Start

				local Mod = SmallMod.MakeLight(StartPart.Position, EndPart.Position,10)
			delay(0.1,function()
				for _,Parts in pairs(Mod:GetChildren()) do
					TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Size = Vector3.new(0,0,0)}):Play()
					TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Transparency = 1}):Play()
				end
				game.Debris:AddItem(Mod,0.2)
				game.Debris:AddItem(StartPart,0.2)
				end)	
			end
		end)
		Dust:Play()
		workspace.End.ParticleEmitter.Enabled = true
		workspace.End.Bolts.Enabled = true
		workspace.End.BoltsOne.Enabled = true
		workspace.End.BoltsTwo.Enabled = true
		workspace.End.BoltsThree.Enabled = true
		workspace.End.PointLight.Enabled = true
		Sound.Volume = 5
		Sound:Play()
		wait(0.1)
		local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
		game.Debris:AddItem(Mod,0.1)
		local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
		game.Debris:AddItem(Mod,0.1)
		wait(0.1)
		local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
		game.Debris:AddItem(Mod,0.1)
		wait(0.1)
		local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
		game.Debris:AddItem(Mod,0.1)
local Ehum = Target.Parent:FindFirstChild("Humanoid")
local Ehumrp = Target.Parent:FindFirstChild("HumanoidRootPart")		
		chr.Archivable = true
		workspace.End.ParticleEmitter.Enabled = false	
		workspace.End.Bolts.Enabled = false
		workspace.End.BoltsOne.Enabled = false
		workspace.End.BoltsTwo.Enabled = false
		workspace.End.BoltsThree.Enabled = false
		workspace.End.PointLight.Enabled = false
		Ehum:TakeDamage(40)	
		
		
elseif Target and Target.Parent:FindFirstChild("MouseHitBox") and InAir == true or Target.Parent:FindFirstChild("Humanoid") and InAir == false  then
			local ServerStore = game:GetService("ServerStorage")
			local TweenSer = game:GetService("TweenService")
			local LightMod = require(game.ServerStorage.LightingScript)
			local SmallMod = require(game.ServerStorage.SmallLightingScript)
			ArmAnim:Play()
			spawn(function()
				for i = 1,4 do
					local StartPart = script.StartPart:Clone()
					StartPart.Parent = workspace
					StartPart.CFrame = Target.Parent:FindFirstChild("MouseHitBox").Parent.HumanoidRootPart.CFrame * CFrame.new(math.random(-2,2),math.random(-2,2),math.random(-2,2))

					local EndPart = script.EndPart:Clone()
					EndPart.Parent = workspace
					EndPart.CFrame = StartPart.CFrame * CFrame.new(math.random(-1,1),math.random(-1,1),math.random(-1,1))

					local Mod = SmallMod.MakeLight(StartPart.Position, EndPart.Position,4)
					wait(0.15)
					for _,Parts in pairs(Mod:GetChildren()) do
						TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Size = Vector3.new(0,0,0)}):Play()
						TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Transparency = 1}):Play()
					end
					game.Debris:AddItem(Mod,0.2)
					game.Debris:AddItem(StartPart,0.2)
					game.Debris:AddItem(EndPart,0.2)
				end
			end)

			workspace.Start.CFrame = Target.Parent:FindFirstChild("HumanoidRootPart").CFrame * CFrame.new(0,math.random(100,150),0)
		    workspace.End.CFrame = Target.Parent:FindFirstChild("HumanoidRootPart").CFrame 
		
		  
		spawn(function() 
			
				for i = 1,10 do	
					wait()
					local StartPart = script.StartPart:Clone()
					StartPart.Parent = workspace
					StartPart.CFrame = workspace.Start.CFrame * CFrame.new(math.random(-4,8),math.random(4,6),math.random(-4,8))

				    local EndPart = game.Workspace.Start
				
				    
				
					local Mod = SmallMod.MakeLight(StartPart.Position, EndPart.Position,10)
					delay(0.1,function()
						for _,Parts in pairs(Mod:GetChildren()) do
							TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Size = Vector3.new(0,0,0)}):Play()
							TweenSer:Create(Parts,TweenInfo.new(0.2,Enum.EasingStyle.Quad),{Transparency = 1}):Play()
						end
						game.Debris:AddItem(Mod,0.2)
						game.Debris:AddItem(StartPart,0.2)
					end)	
				end
			end)
		Dust:Play()
		workspace.End.ParticleEmitter.Enabled = true
		workspace.End.Bolts.Enabled = true
		workspace.End.BoltsOne.Enabled = true
		workspace.End.BoltsTwo.Enabled = true
		workspace.End.BoltsThree.Enabled = true
		workspace.End.PointLight.Enabled = true
		
			Sound.Volume = 5
			Sound:Play()
			wait(0.1)
			local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
			game.Debris:AddItem(Mod,0.1)
			local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
			game.Debris:AddItem(Mod,0.1)
			wait(0.1)
			local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
			game.Debris:AddItem(Mod,0.1)
			wait(0.1)
			local Mod = LightMod.MakeLight(game.Workspace.Start.Position, game.Workspace.End.Position,20)
			game.Debris:AddItem(Mod,0.1)
			local Ehum = Target.Parent:FindFirstChild("Humanoid")
			local Ehumrp = Target.Parent:FindFirstChild("HumanoidRootPart")		
			chr.Archivable = true
		    Ehum:TakeDamage(40)	
		    local KickedDownAnimation = Target.Parent:FindFirstChild("Humanoid"):LoadAnimation(script.KickedDown)
		    KickedDownAnimation:Play()
		    delay(0.4,function()
			KickedDownAnimation:Stop()
		    end)
		    local KickDownEfx = require(game.ServerStorage.KickDownVfx)
		    KickDownEfx.KickFunction(Target.Parent:FindFirstChild("HumanoidRootPart"),0.6)
			local KickVelocity1 =  Instance.new("BodyVelocity",Target.Parent:FindFirstChild("HumanoidRootPart"))
			KickVelocity1.Velocity =  chr.HumanoidRootPart.CFrame.LookVector * 20 + chr.HumanoidRootPart.CFrame.UpVector * -200
			KickVelocity1.MaxForce =  Vector3.new(math.huge,math.huge,math.huge)
			game.Debris:AddItem(KickVelocity1,0.1)
	end
end)
while wait() do
	for i,v in pairs(workspace:GetChildren()) do
		if v:IsA("Model") and v:FindFirstChild("Humanoid") then
			v:FindFirstChild("Humanoid").StateChanged:Connect(function(OldState,NewState)
				if NewState == Enum.HumanoidStateType.Freefall then
					if not InAir then
						if v:FindFirstChild("Humanoid"):GetState() == Enum.HumanoidStateType.Freefall then
							InAir = true
							print("Second Part Has Started")
							delay(3,function()
								InAir = false
							end)	
						end	
					end	
				elseif NewState == Enum.HumanoidStateType.Landed then
					InAir = false
					if v.HumanoidRootPart:FindFirstChild("BodyVelocity") then
						v.HumanoidRootPart:FindFirstChild("BodyVelocity"):Destroy()
						workspace.End.ParticleEmitter.Enabled = false	
						workspace.End.Bolts.Enabled = false
						workspace.End.BoltsOne.Enabled = false
						workspace.End.BoltsTwo.Enabled = false
						workspace.End.BoltsThree.Enabled = false
						workspace.End.PointLight.Enabled = false
					end
				end 
			end)
		end
	end
end

this is the whole code
plus server script

print("Hi")

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    print(player.Name .. " joined the game!")
	print("Hi")

	local Character = player.Character or player.CharacterAdded:Wait()

	local MouseBoxPart = script.MouseHitBox:Clone()
	MouseBoxPart.Parent = Character
	MouseBoxPart.CFrame = Character:WaitForChild("HumanoidRootPart").CFrame

	local MBoxWeld = Instance.new("Weld",Character:WaitForChild("HumanoidRootPart"))
	MBoxWeld.Part0 = MouseBoxPart
	MBoxWeld.Part1 = Character:WaitForChild("HumanoidRootPart")
	MBoxWeld.C0 = MBoxWeld.Part1.CFrame:ToObjectSpace(MBoxWeld.Part0.CFrame * CFrame.new(0,0,0))
end)

Players.PlayerRemoving:Connect(function(player)
	print(player.Name .. " left the game!")
end)

Could you elaborate please? Within every topic you create on DevForum, you need to be specific about what the issue is and what you are trying to achieve.

it keeps saying attempt to index nil with parent

Can you provide more code? You have like 5 different variables that could all be nil.

Is this in a local script and/or runs immediately? Most likely that MouseHitBox doesn’t exist yet.

So, what is the Target value being assigned to?

There is no point to using ‘FindFirstChild’ if you’re just going to index it without checking if it exists. Just use .MouseHitBox.

1 Like

Please update your topic’s description. Tell us what the issue is and what you are trying to achieve. You can’t just send only one line of code and expect us to fix the whole thing for you. Show us the whole code.

alright i have updated the whole code is should show up

It would greatly help to see the line number, and also just the line of which the error happens. It’s not helpful to see ‘attempt to index nil with Parent’ with no line number, because it could be many things in your code. We are not mind-readers, tell us how to help you.