i am trying to make a brick that when clicked will slowly drain your health. the code goes as follows:
script.Parent.MouseClick:Connect(function(plr) local h = plr.Character.Humanoid for i = 100, 0, 1 do h.Health = i end end)
it should work fine from what i understand, but whenever i click on the brick nothing happens. I'm pretty sure that it doesnt have anything to do with the variables because whenever i type:
script.Parent.MouseClick:Connect(function(plr) local h = plr.Character.Humanoid h.Health = 0 end)
it works, so the variables arent the problem.
Help would be appreciated
A better way is to use tweenservice
local time = 8 game:GetService('TweenService'):Create(plr.Character.Humanoid,TweenInfo.new(time),{Health = 0}):Play()
You need to add a clickDetector to your part. You also will want to edit your for loop
script.Parent.ClickDetector.MouseClick:Connect(function(plr) local h = plr.Character.Humanoid for i = 100, 0, -1 do h.Health = i end end)
This should fix your program