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

how do i make code that slowly does damage to a plyr, when they r in it?

Asked by 4 years ago

Here is a script that slowly does damage while the player is in it. Unfortunately it doesn't work all the time. I put it in a block and put the blocks down different places so when the player walks through it it does damage.

~~~~~~~~~~~~~~~~~

local damage = 1 local touched local timebeforeotherdamage = 1

01script.Parent.Touched:Connect(function(hit)
02    if hit.Parent:FindFirstChild("Humanoid") then
03        if touched == false then
04              touched = true
05        repeat
06     if touched == true then
07        hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
08 
09end
10wait(timebeforeotherdamage)
11        until
12        hit.Parent.Humanoid.Health == 0
13        end
14 
15    end
View all 28 lines...

sometimes it will do a little damage, but when you go out of the block and back in, it does A LOT. The code looks fine to me so I don't know whats wrong...

0
Use FindPartsInRegion3 (https://developer.roblox.com/en-us/api-reference/function/WorldRoot/FindPartsInRegion3) instead, it is way more reliable in this situation. Benbebop 1049 — 4y
0
I will just warn you guy I'm still learning, so talk to me like a 5 year old astonplep 32 — 4y
0
A region3 is made by specifying the top right and bottom left points of the box you want to do damage in. Once you have the region made, you can find parts in it and do damage to the humanoid. SteamG00B 1633 — 4y
0
I would highly suggest Region3s, to learn how to get players in a Region3, a good example is AlvinBlox's Robbable Bank Tutorial, which includes the use of region3s. Nckripted 580 — 4y
0
ok astonplep 32 — 4y

1 answer

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

This might work! Put this in a script inside of your damage part. Change the wait(1) to change how many seconds you want to wait in between damaging. Change the hum:TakeDamage(50) to how much damage you want to do. If this doesn't work or gives an error, tell me in the comments of this answer and I'll fix my code.

01local part = script.Parent
02local debounce = false
03part.Touched:Connect(function(touched)
04    local hum = touched.Parent:FindFirstChild("Humanoid") --if its a player
05    if hum then
06        if debounce == false then
07            hum:TakeDamage(50) --Damage you want to do
08            wait(0.5) --wait whatever amount of seconds
09            debounce = true
10        end
11    end
12end)

**EDIT: you can make it the part's transparency 1 and cancollide false to make it sort of an invisible "damage zone"

Make sure it's a server script and inside of your part. Hope this works :)

0
That didn't work astonplep 32 — 4y
0
Errors? proqrammed 285 — 4y
0
yes astonplep 32 — 4y
0
as a server script do you mean a normal script, and it didn't work when you stoped moving astonplep 32 — 4y
View all comments (2 more)
0
He's asking for the errors, not if you got errors. SteamG00B 1633 — 4y
0
no errors astonplep 32 — 4y
Ad

Answer this question