Hello everyone, so today I was making gamepasses and I wanted to have a god coil. So when the player buys the coil, the person can never die. I am not really sure how to make a coil that can have that because, when you touch a part, your health goes to 0 no matter what. Does anyone know how to make one that makes you never die? Here is the death script, and you can see what I am talking about.
function DeathTouch(hit)
if hit.Parent:FindFirstChild('Humanoid') then
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)
You can replace the killbrick damage with Humanoid:TakeDamage(amount of damage).
Then you can add a starterCharacterScript so that as long as they have the coil, they’ll spawn in with an infinite invisible forcefield.
Just a note: if the game this is for is a game based on fighting, this gamepass will make your players think it’s Pay To Win.
If i were you, I would create a new value called “god coil” when the player joins, check if that player has the certain value(basically if they have the gamepass), and when you do the touched event, you can just go like this:
function DeathTouch(hit)
local char = hit.Parent
local player = game.Players:FindFirstChild(char.Name)
if hit.Parent:FindFirstChild('Humanoid') and player.Folder.HasGodCoil.Value == false then
hit.Parent.Humanoid.Health = 0
else
print("Has god mode!")
end
end
health = 9e9
active = false
script.Parent.Equipped:connect(function()
active = true
end)
script.Parent.Unequipped:connect(function()
active = false
end)
while wait(0.1) do
if active then
script.Parent.Parent.Humanoid.Health = script.Parent.Parent.Humanoid.MaxHealth + health
end
end
I think I did that right, just let me know if I did that wrong. Thanks :)))
Yeahhh, that didn’t work because I died automatically. I changed the kill part to -100 idky it’s still doing this.
function DeathTouch(hit)
if hit.Parent:FindFirstChild('Humanoid') then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -100
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)
The best solution, as I said, is to add an infinite forcefield to the player when they spawn in.
--put in StarterPlayer > StarterCharacterScripts as a ServerScript
local character = script.parent.parent.Character
local forceField = instance.New("forceField")
forceField.Parent = character
forceField.Visible = false
forceField.Active = true
And replace killbrick scripts with this:
local killbrick = script.Parent
local function onTouch (otherPart)
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
humanoid:TakeDamage(100)
end
killbrick.Touched:Connect(onTouch)
local killbrick = script.Parent
local function onTouch (otherPart)
local humanoid = otherPart.Parent:FindFirstChildWhichIsA("Humanoid")
humanoid:TakeDamage(100)
end
killbrick.Touched:Connect(onTouch())