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
01function damageplr(hit)
02wait(1.0)
03if hit.Parent.Head then
04hit.Parent:FindFirstChild("Humanoid").Health =hit.Parent:FindFirstChild("Humanoid").Health - 2
05end
06end
07 
08function TouchEnd(hit)
09 
10end
11 
12script.Parent.Touched:connect(function(hit)
13wait()
14repeat damageplr() until TouchEnd()
15hit.Anchored = false
16end)
17 
18script.Parent.TouchEnded:connect(TouchEnd)
19script.Parent.Touched:connect(damageplr)

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

01local CanTouch = true
02script.Parent.Touched:Connect(function(part)
03    local hum = part.Parent:FindFirstChild("Humanoid")
04    if CanTouch and hum then
05        CanTouch = false
06        repeat
07        hum.Health = hum.Health - 10
08        wait(1)
09        until hum.health = 0
10        CanTouch = true
11    end
12end)

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)

01local damage = 10
02  local touched
03        local timebeforeotherdamage = 2
04 
05 
06 
07script.Parent.Touched:Connect(function(hit)
08    if hit.Parent:FindFirstChild("Humanoid") then
09        if touched == false then
10              touched = true
11        repeat
12     if touched == true then
13        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
14 
15end
View all 34 lines...
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