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

How do I make a value decrease over time or on touched?

Asked by
Xoqex 75
11 years ago

I'm practicing but not sure how to make a value decrease like say I try to make a brick that makes your health -20 on hit, but not 20 health, just subtracts 20 from your current health. How do I do that? And I assume it would be the same for reflectance or something like that too.

1script.Parent.Touched:connect(function(hit)
2    print(hit)
3    hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health -20 --Doesn't work
4end)

thanks

2 answers

Log in to vote
1
Answered by 11 years ago
01local debounce = false
02 
03script.Parent.Touched:connect(function(obj)
04    if debounce == true then return end --To make it not run all at once when you hit it
05 
06    debounce = true
07    if obj.Parent:FindFirstChild("Humanoid") then
08        local human = obj.Parent.Humanoid
09        human.Health = human.Health - 20
10    end
11 
12    wait(.2)
13    debounce = false
14end)
0
Hmm I tried it but it's erroring at the ) by the end, so I removed it and then the "if obj.Parent:FindFirstChild("Humanoid") then" errored Xoqex 75 — 11y
0
Is that with this current version? I edited it because I forgot something VariadicFunction 335 — 11y
0
Thanks that worked! Do you think you can PM me why the script has to be so complicated and teach me a little about it? Xoqex 75 — 11y
0
Sure VariadicFunction 335 — 11y
Ad
Log in to vote
0
Answered by 11 years ago
1game.Workspace.Part.Touched:connect(function(hit) --Rename "Part" with whatever the name is of the brick you want touched.
2print(hit)
3hit.Parent.Humanoid.Health = 0
4end)

This should work.

Answer this question