Inf Health When Touching A Certain Part

So if you have ever watched Naruto, then you should know about the Jashin Technique. It’s a technique where when a person is standing on a specific circle, they can’t die, and any damage done to that person is reflected to whoever afflicted the damage. So I’m trying to make something similar to that… Kind of exactly the same… But there’s a problem. I don’t know how to make it so that it only works when the player is touching it and when they’re not, it stops working.

  1. What do you want to achieve? So what I need is: when the player is on the part, they become invincible. If they walk off of the part, they revert their health back to what is was.

  2. What is the issue? The issue is I got half of it done so far, but I just need to make it so that when the player is not touching the part, they’re health goes back and they can take damage.

  3. What solutions have you tried so far? I’ve searched the DevForums and google thoroughly and didn’t find anything related to my problem. To make things simple, it’s like a speed boost part, but for health and it stops the speed boost/health boost when you’re not touching it.

local Circle = script.Parent

local function Touching(part)
local parent = part.Parent
if game.Players:GetPlayerFromCharacter(parent) then
parent.Humanoid.MaxHealth = 200
wait (5)
parent.Humanoid.MaxHealth = 100
end
end

So as you can see, when the player touches the circle their health becomes 200, and after 5 seconds it goes back to 100. So I think I need to change the “wait (5)” to something like “wait until not touching” but I’ve tried several similar lines and I got nothing.

you could do Circle.TouchEnded:Wait()

1 Like

And where would I put that? Do I Replace it with “wait (5)”?

made a debounce local debounce = false

Circle.TouchEnd:Conect(function(part)
    debounce = true
end)

and after the debounce is true change health back to what it was.

1 Like

Also yes you could replace the wait(5) with Circle.TouchEnd:Wait() and without the debounce

1 Like

Alright thanks, but what about the
local debounce = false

Circle.TouchEnd:Conect(function(part)
    debounce = true
end)

Where do I put that?
Edit: Ohhh at the end?

local Circle = script.Parent
local Debounce = false


local function Touching(part)
  local parent = part.Parent
  if game.Players:GetPlayerFromCharacter(parent) then
    parent.Humanoid.MaxHealth = 200
    repeat wait() until Debounce == true
    parent.Humanoid.MaxHealth = 100
   end
 end
 local function TouchEnd(part)
   local parent = part.Parent
   if game.Players:GetPlayerFromCharacter(parent) then
     Debounce = true
   end
end
1 Like

Wow thanks for all that, I’ll test it out.

Sorry but something isn’t right. I’ll try to fix it.

sorry the debounce is not the same I said local Debounce but then said debounce

1 Like

So it’s not local? Or… What, I don’t understand. Sorry, I don’t know too much about scripting.
If you’re talking about the capital d I realized that already and changed it but it still didn’t work

it is not right because it is not uppercase at the begining

1 Like

you shouldn’t have it repeat wait until debounce is == true, if you touch it 5 times you will have a 5 time shield after each debounce. Just return it.

1 Like

sorry, it got myself in a loop hole. sorry again

2 Likes

So I replaced repeat with return, there’s an error

return wait() until debounce == true

try putting your code in a

if debounce == true then

end
1 Like
local part = script.Parent -- path part you want them be on, in my case its the scripts parent
local touching = {}

part.Touched:Connect(function(hit)
	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	if touching[player.Name] then return end
    touching[player.Name] = hit.Parent.Humanoid.Health
	hit.Parent.Humanoid.Health = math.huge
	
end)

part.TouchEnded:Connect(function(hit)
	
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if not player then return end
	if not touching[player.Name] then return end
    hit.Parent.Humanoid.Health = touching[player.Name]
	touching[player.Name] = nil
	
end)

I dont know if this would work but it might
it was edited from a slightly broken tool script. it worked fine except i messed up tool cloning

1 Like

you should do if touching[plr.Name] and touching[plr.Name] == nil or touching[plr.Name] then return end

1 Like

I don’t want it to be a player of my choosing. It’s like whoever created the part is the only person who gets to use it

you can just do if the player activated the move you get a shield.

1 Like