How would i check if a part is there or not there?

So im trying to check if a part is on the player but im not sure how to, how would i check if a part is not and is there?

local shield = game.ServerStorage.shield:Clone()
local character = player.Character or player.CharacterAdded:Wait()
	shield.Parent = character
      while shield do
	  character.Humanoid.Health = 100
end

Check for the part’s parent if the reference is still there. If you’re looking for a non-referenced part, use FindFirstChild().

You can use some functioning to keep health on player, it’d be better if you’d disable causing damage on the tool or sword that is being hit against the player, but in your case here:

Make a function that keeps health 100

local HealFunc

local function Heal(Humanoid)
   Humanoid.Health = 100
   HealFunc = Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
        Humanoid.Health = 100
   end)
end

local function UnHeal()
     HealFunc:Disconnect()
end)

Now you got these done, use an efficient way to check for shield if it’s on the character, and such would be by using:

Instance.ChildAdded Run an if check to see if the part added to the character is the shield and use heal() if so
Instance.ChildRemoved Run an if check to see if the part removed from the character is the shield and use unheal() if so

This is more optimized way of handling your code instead of using while loop where it’s completely unnecessary

but how would i keep the player’s health at 100 and not go down

But i want to check if the player has a shield, not if the player loses some health

I think you’re referring to something else and you’re probably talking about a forcefield. To enable some kind of “god-mode”, use Humanoid.HealthChanged event to check if the humanoid’s health changes. If it does, reset Humanoid.Health to 100.

Read the second section of my post

it says attempt to index nil with Disconnect

Use an if statement

(Checking if something is there):
If game.Workspace:FindFirstChild(“Whatever”) then (etc)

(Checking if something is still there):
local part = game.Workspace.Part
If part ~= nil then (etc)