How to make a player get 10 damage every 1 secont if he is inside of a part

Hello develupers This is a very simple. I want to make a player get 10 damage every 1 second if he is inside of a part I maked a sinple script with touched function and
With debounce.
But the player don’t get damage if he is stopped. I want to make player get damage if he is inside of the part. There’s a way to make this? Thanks for all help.
The part is can collide set off

4 Likes

The player is put in a table once made contact. Every second, have the script check each tagged player if they are still touching. if not, or their HP is 0, remove from the table. If still touching, 10 damage.

1 Like

No. I want to make a damage area that if you enter you get 10 damage every second.

Do it as @Program48656c707573 said, using a CanCollide off Part (that can be Transparent if you want, but have CanTouch set to true), but also check to see if HumanoidRootPart.BasePart | Roblox Creator Documentation is less than .1 (or something close to 0) to check if the player is moving or not.

1 Like

I would use zone module for something like this

--using zone functions/methods/events (in this case an event) obtain Zone's modulescript in replicated storage(see installation walkthrough)
local Zone = require(game:GetService("ReplicatedStorage").Zone)
--initialize a zonegroup, i.e. checkpoints, zones must be something a player
--touches or passes through.

local groupzone1= game.Workspace.groupzone1--Location of Block in which you want the player to see if hes inside

local zone1= Zone.new(groupzone1)

--categorizes the zones on map as a actual zone within ZonePlus module

--Checks on player entering, who that player was
zone1.playerEntered:Connect(function(player)--obtains player
--set a bool to true and loop every second or etc damage, keep checking if bool is true if not, break loop
end)

zone1.playerExited:Connect(function(player)--obtains player
--make a bool to identify that the player left in entered event and break loop
end)

Please note, the bool would have to be identifiable for the player.Name in a sort of dictionary/table so you need to understand tables for this, particularly table.insert and table.remove setting values in table…

1 Like

But there’s a way to make like a area of damage. That detects if a player is inside or no of the part.

can’t you just use a loop something like

humanoidtouch = false
local part = script.parent
part.touched:Connect(function(player)
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid then
humanoidtouch = true
while humanoidtouch = true do 
wait(1)
humanoid.Health = humanoid.Health - 10
  end
 end
end)
part.Touchended:connect(function()
humanoidtouch = false
end)

you get the idea, i made a lotta coding grammer issues i think but you can correct them

1 Like

Yeah let me try it. if not work I will try other solutions👍

Insert a Part in Worspace and name it: “KillPart”

-- Localscript:

local player = game.Players.LocalPlayer

local killPart = game.Workspace:WaitForChild("KillPart")

local Found = false

while wait(1) do -- Every second the Health will decrease. U can change it.

	for i, v in pairs(killPart:GetChildren()) do

		Found = false
		local region = Region3.new(v.Position - (v.Size/2),v.Position + (v.Size/2))

		local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())


		for _, part in pairs(parts) do
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				Found = true
				break
			else
				Found = false



			end
		end



		if Found == true then

character.Humanoid.Health -= 1

end

end

end
2 Likes

make it a script inside the part

That’s exactly what @Program48656c707573 and I suggested.
A Part, that when Touched will do 10 damage per second, unless the player is standing still.

You have to come up with a script. This forum is for help with your script, not for writing one for you.
Many times people can’t just write you a script since they don’t know how your game is set up.

2 Likes

Oh now I understand let me try it

if you want you could add an debounce so it dosn’t - 10 health per bodypart, tell me if you need so

1 Like

Use Region3 to detect when a player is inside an area

Why not try using a Region3 instead, of course if you have to move the area of damage, then i’d recommend using a part.
Region3 is basically just an 3d volume the game designate’s.

2 Likes

The all solutions Is valid thanks all for help.

2 Likes