What is wrong with shield script

So im really confused on why this isn’t working, it isn’t destroying the shield for some reason and it isn’t working, why?

game.Players.PlayerAdded:Connect(function(player)
local char = player.Character or player.CharacterAdded:Wait()
local shield = char:WaitForChild("shield")

player.BulletHit:GetPropertyChangedSignal("Value"):Connect(function() 
if player.BulletHit.Value < 0 then 
		player.BulletHit.Value = 0
	end
end)

shield.Touched:Connect(function(hit)
	if hit.Parent == hit.Parent:FindFirstChild("Bullet") then
		player.BulletHit.Value = player.BulletHit.Value - 1 
			player.BulletHit.Changed:Wait()
			if player.BulletHit.Value <= 0 then
				shield:Remove()
				print("removed")
				end
			end	
		while shield do
		wait()
		player.Character.Humanoid.Health = 100
	end
		if not shield then
			player.Character.Humanoid.Health = 100
		end
	end)
end)

This line might be causing the next line to not run if the BulletHit value doesn’t change. Try to remove this line and see what happens.

1 Like

nope, that did nothing either

try adding a debug print of the value changing somewhere just out of curiosity

Wait is this a server script or local script

it’s a serverscript

1 Like

is it at least making it past the if statement in the Touched event?

i figured out the problem, i had to move it to another place in a script. Thanks so much for helping and sorry to waste any of your time

1 Like

Ah I am assuming it was placed under a yielding function?

It was no problem at all, glad you found a solution :+1:

1 Like