How come headshot code doesn't work?

I have this FE edited RRP2 gun system for my game’s gun system. I want it to be able to do double the damage when it hits the target’s head. I’ve got the server side set up, but for some reason the client side doesn’t work. I’ve gotten no errors, I’ve added ends to fix the red lines, but it turns a bunch of the code blue and said it should change to local when it didn’t do that before. Help?

 if hitObject and hitObject.Parent then
					local hitHumanoid = hitObject.Parent:FindFirstChild("Humanoid")
					local hitHead = hitObject.Parent:FindFirstChild("Head")
					
					if hitHumanoid then
						local hitPlayer = game.Players:GetPlayerFromCharacter(hitHumanoid.Parent)
						if MyPlayer.Neutral or hitPlayer then
							TagHumanoid(hitHumanoid, MyPlayer)
							script.Parent.DamageEvent:FireServer(hitHumanoid)
							
					if hitHead then
						local hitPlayer = game.Players:GetPlayerFromCharacter(hitHead.Parent)
						if MyPlayer.Neutral or hitPlayer then
							TagHumanoid(hitHead, MyPlayer)
							script.Parent.HitHeadEvent:FireServer(hitHead)	
							
							if bullet then
								
								bullet.BrickColor = BrickColor.new("Maroon")
								
								bullet.Material = "Pebble"
								
								
								local randomnumber = math.random(1, 3)---randomized blood hit sound
								if randomnumber == 3 then 
									script.Parent.Handle.HitSounds.BloodHit3:Play()
								end
								if randomnumber == 2 then 
									script.Parent.Handle.HitSounds.BloodHit2:Play()
								end	
								if randomnumber == 1 then 
									script.Parent.Handle.HitSounds.BloodHit1:Play()
								end
								end
							
							
								
							
							spawn(UpdateTargetHit)
						end
					end
				end

i think your end are all messed up

but its hard to tell because your tabs are all over the place

if A = true then -- this is the outer if
    if B = false then -- this is the inner if
        -- code
    end -- this will end the inner if
end -- this with end the outer if
1 Like

Exactly what @5uphi said, it needs two more ends at the end… plus you never defined hitObject.

Also is there more to the script than what is shown? What is this for: