spawn(function()
while shield.IsInUse.Value == true do
wait()
player.Character.Humanoid.Health = 100
if not shield:FindFirstChild("IsInUse") then
break
end
end
end)
local player = game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local shield = char:WaitForChild("shield")
shield.Touched:Connect(function(hit)
if hit.Parent == hit.Parent:FindFirstChild("Bullet") then
player.BulletHit.Value = player.BulletHit.Value - 1
repeat wait() until player.BulletHit.Value == 0
end
if player.BulletHit.Value <= 0 then
shield:Destroy()
shield.IsInUse.Value = false
spawn(function()
while shield.IsInUse.Value == true do
wait()
player.Character.Humanoid.Health = 100
if not shield:FindFirstChild("IsInUse") then
break
end
end
end)
if not shield:FindFirstChild("IsInUse") then
player.Character.Humanoid.Health = 100
end
end
end)
local ShieldCor = coroutine.wrap(function()
wait()
player.Character.Humanoid.Health = 100
if not shield:FindFirstChild("IsInUse") then
break
end
end)
while shield.IsInUse.Value == true do
ShieldCor()
end
im destroying the shield and it’s erroring that it can’t find the value in the shield. So i want it to stop erroring
local player = game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local shield = char:WaitForChild("shield")
shield.Touched:Connect(function(hit)
if hit.Parent == hit.Parent:FindFirstChild("Bullet") then
player.BulletHit.Value = player.BulletHit.Value - 1
repeat wait() until player.BulletHit.Value == 0
end
if player.BulletHit.Value <= 0 then
shield:Destroy()
shield.IsInUse.Value = false
local ShieldCor = coroutine.wrap(function()
wait()
player.Character.Humanoid.Health = 100
end)
while shield.IsInUse.Value == true do
ShieldCor()
end
if not shield:FindFirstChild("IsInUse") then
player.Character.Humanoid.Health = 100
end
end
end)
repeat
-- Your code here
until not shield:FindFirstChild("IsInUse")
One thing I noticed is how you put if not shield:FindFirstChild("IsInUse") then, I believe you meant to put shield:FindFirstChild("IsInUse").Value. Let me know if either of those help!
I would also like to point out that spawn is a very bad practice because of how it can delay depending on how much stuff you have. Here is a post that I searched that should go better into detail about it: Post here
while shield:FindFirstChild('IsInUse') and shield.IsInUse.Value do
wait()
player.Character.Humanoid.Health = 100
end
Edit: This will stop the rest of your lines until IsInUse does not exist or value is set to false, if you dont want this to happen wrap it into a coroutine.