Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
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.

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. doggybite1 100 — 4y

1 answer

Log in to vote
0
Answered by
crueluu 169
4 years ago
Edited 4 years ago

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)
0
plus theres a much easier way to execute this. crueluu 169 — 4y
0
And Are You Trying To Create A Safe Zone Or Something Similar? crueluu 169 — 4y
0
Thats how I had it before, but it continues doing damage even when they are out of the part. astonplep 32 — 4y
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. astonplep 32 — 4y
View all comments (5 more)
0
here i wrote a script hope it helps you can change the duration which is basically how much time until the other damage crueluu 169 — 4y
0
so did it work? crueluu 169 — 4y
0
It seems to be working just fine. astonplep 32 — 4y
0
Thank you so much! This is what I've been looking for, for a long time! astonplep 32 — 4y
0
Happy To Help :) crueluu 169 — 4y
Ad

Answer this question