Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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)

4 comments

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

0

Is that with this current version? I edited it because I forgot something

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?

0

Sure

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.