Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a script which does damage while the player is in the block?

function damageplr(hit)
wait(1.0)
if hit.Parent.Head then
hit.Parent:FindFirstChild("Humanoid").Health =hit.Parent:FindFirstChild("Humanoid").Health - 2 
end
end

function TouchEnd(hit)
	
end

script.Parent.Touched:connect(function(hit)
wait()
repeat damageplr() until TouchEnd()
hit.Anchored = false
end)

script.Parent.TouchEnded:connect(TouchEnd)
script.Parent.Touched:connect(damageplr)

This script will stop doing damage once the player gets inside the part.



local CanTouch = true
script.Parent.Touched:Connect(function(part)
	local hum = part.Parent:FindFirstChild("Humanoid")
	if CanTouch and hum then
		CanTouch = false
		repeat
		hum.Health = hum.Health - 10
		wait(1)
		until hum.health = 0 
		CanTouch = true
	end
end)

This one kinda works but once the player leaves it continues doing damage, because of until hum.Health = 0

I know this code sucks, but I'm a beginner coder.

1 comment

0

This probably isn't the best solution, but every time you wanna do damage, you can see if the Player's position is within a certain coordinate bound, this solution really only works well if the part is rectangular and is harder to calculate otherwise.

1 answer

✓ Accepted answer

I Think it has to do with the second script line 9 when using Until you Should Use double equal signs, so Instead Of "Until hum.Health = 0" do "Until hum.Health == 0"

look try this sorry if doesnt work but i tried my best! edit: there was a mistake so i had to edit it(should work properly now)

local damage = 10
  local touched
        local timebeforeotherdamage = 2



script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if touched == false then
              touched = true
        repeat
	 if touched == true then
        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
       
end 
wait(timebeforeotherdamage)
        until
        hit.Parent.Humanoid.Health == 0 
        end

    end
    repeat
    wait()
    until
    touched == false





end)
script.Parent.TouchEnded:Connect(function(hit)
    touched = false
end)

9 comments

0

plus theres a much easier way to execute this.

0

And Are You Trying To Create A Safe Zone Or Something Similar?

0

Thats how I had it before, but it continues doing damage even when they are out of the part.

0

I'm using this in poison gas. When the player out of it they don't take damage, but when they are in do.

0

here i wrote a script hope it helps you can change the duration which is basically how much time until the other damage

0

so did it work?

0

It seems to be working just fine.

0

Thank you so much! This is what I've been looking for, for a long time!

0

Happy To Help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.