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
10 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.

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

thanks

2 answers

Log in to vote
1
Answered by 10 years ago
local debounce = false

script.Parent.Touched:connect(function(obj)
    if debounce == true then return end --To make it not run all at once when you hit it

    debounce = true
    if obj.Parent:FindFirstChild("Humanoid") then
        local human = obj.Parent.Humanoid
        human.Health = human.Health - 20
    end

    wait(.2)
    debounce = false
end)
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 — 10y
0
Is that with this current version? I edited it because I forgot something VariadicFunction 335 — 10y
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 — 10y
0
Sure VariadicFunction 335 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
game.Workspace.Part.Touched:connect(function(hit) --Rename "Part" with whatever the name is of the brick you want touched.
print(hit)
hit.Parent.Humanoid.Health = 0
end)

This should work.

Answer this question