God coil script look over

Hello everyone, if you commented on my last post you might ask why I am doing this again, reason is, no one really commented so I am making a new topic, SO basically for a gamepass, I want it to be where if someone has a god coil then they don’t take damage, I typed in a script where the person doesn’t take damage if they have it but they still die. Not really sure how to make this work. If anyone knows how to do this, please leave response that is explained well (I’m pretty new to coding) Here is my script.

local ServerStorage = game:GetService("ServerStorage")
local GodCoil = game.ServerStorage.GodCoil



function DeathTouch(hit)
	local char = hit.Parent
	local player = game.Players:FindFirstChild(char.Name)
	if hit.Parent:FindFirstChild("Humanoid") and player.Godcoil == true then
		hit.Parent.Humanoid.Health = false
	else 
		hit.Parent.Humanoid.Health = 0
	end
end

for _,v in pairs(workspace:GetChildren()) do
	if v.Name == 'killme' then
		v.Touched:Connect(function(hit)
			DeathTouch(hit)
		end)
	end
end

workspace.ChildAdded:Connect(function(Child)
	if Child.Name == 'killme' then
		Child.Touched:Connect(function(hit)
			DeathTouch(hit)
		end)
	end
end)

just use Owns GamePass Async to check whether they have the gamepass or not. If they don’t damage them. If they do, do nothing. Or, alternatively, you can check whether they have the god coil equipped (by checking if it is in their character).

Do you mind giving me an example of code? if not that’s fine. But how do I check if they have it in their inventory.

you can just do this:

local toolname = "Coil" --change to the tool name
part.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        if not player.Backpack:FindFirstChild(toolname) and not player.Character:FindFirstChild(toolname) then
            player.Character.Humanoid:TakeDamage(100)
        end
    end
end)

ahhh, ok, I will try this out on my break.

Thank you for explaining this for me.

Old post without edit

Wait, doesn’t this script allow a chance for non-owner players to survive when health regeneration happens at the moment the player takes 100 damage?

(Just in case the sample script was kept unchanged)

This would only apply if you were going to deal exactly 100 damage and you were using the default health regen script. Otherwise, don’t mind me at all.

Nvm it was an old bug that has already been patched, sorry and don’t worry.

There was a bug where if the player took 100 damage when regenerating its health it would add 1 hp thus the player wouldn’t die afterwards.

(The actual newer script won’t regen if the player has full hp, thus fixing the bug)

Well, the default health 100, so I don’t think they would.