Make Block Constantly Damage Player on Touch?
I have a block where I want it to do damage to the player at a constant rate (like 5 damage a second). Basically, when the player is on the block, the block will remove 5 health from that player each second. I want it so that it will still do damage to the player at a constant rate regardless of whether or not the player is standing still. I would also want the player to be slowed down when the player is on it. How would I do it? Here's what I have so far:
01 | local CollectionService = game:GetService( "CollectionService" ) |
02 | local part = CollectionService:GetTagged( "DamagePart" ) |
04 | for _, TaggedPart in pairs (part) do |
06 | function onTouched(hit) |
07 | if onblock = = false then |
09 | local h = hit.Parent:findFirstChild( "Humanoid" ) |
11 | while onblock = = true do |
12 | h.Health = h.Health - 5 |
19 | function stopdamage(hit) |
21 | hit.Parent:findFirstChild( "Humanoid" ).WalkSpeed = 16 |
23 | TaggedPart.Touched:Connect(onTouched) |
24 | TaggedPart.TouchEnded:Connect(stopdamage) |
This is quite buggy and does inconsistent damage. It also will sometimes not do damage when the player is standing still. If you could tell me what I did wrong and paste a working code snippet in I would really appreciate it. Thanks for your help :)
Also while you're at it can you please answer this question for me too? scriptinghelpers.org/questions/115188/bullets-are-not-going-through-objects-without-collisions