local EffectEvent = game.ReplicatedStorage.Effect
local players = game.Players
local char = script.Parent.Parent.Parent.Parent
local Humanoid = char:WaitForChild("Humanoid")
local BleedVal = script.Parent.Parent.Parent.Parent.Effects.Preset.Bleeding
local dmgOverTime = 5
local dmgTime = 5
local dmgCD = 3
BleedVal.Changed:Connect(function(val)
EffectEvent:FireClient(players:GetPlayerFromCharacter(char), val, BleedVal)
while val do
task.wait(dmgCD)
dmgTime -= 1
Humanoid:TakeDamage(dmgOverTime)
end
end)
I use a .Changed event to find the value, however it appears that the loop does not stop itself once the value changes.
I don’t know much about lua. I don’t know why am I trying to help you, but I can try, I guess…!
local EffectEvent = game.ReplicatedStorage.Effect
local players = game.Players
local char = script.Parent.Parent.Parent.Parent
local Humanoid = char:WaitForChild("Humanoid")
local BleedVal = script.Parent.Parent.Parent.Parent.Effects.Preset.Bleeding
local dmgOverTime = 5
local dmgTime = 5
local dmgCD = 3
local shouldContinue = true
BleedVal.Changed:Connect(function(val)
EffectEvent:FireClient(players:GetPlayerFromCharacter(char), val, BleedVal)
shouldContinue = val
while shouldContinue do
task.wait(dmgCD)
dmgTime -= 1
Humanoid:TakeDamage(dmgOverTime)
if dmgTime <= 0 then
shouldContinue = false
end
end
end)
I did some changes to make it work. shouldContinue is set to val when the BleedVal changes, and then the loop checks this variable to decide whether to continue or not. Maybe it will help. The loop also checks if dmgTime has reached 0, and if so, sets shouldContinue to false to stop the loop. It can be wrong, let me know if it does not work.
val won’t change when BleedVal.Value changes.
You’ll need to check if the value of BleedVal has changed every time the loop runs, like this:
BleedVal.Changed:Connect(function(val)
EffectEvent:FireClient(players:GetPlayerFromCharacter(char), val, BleedVal)
while BleedVal.Value do -- while the value of BleedVal is true
task.wait(dmgCD)
dmgTime -= 1
Humanoid:TakeDamage(dmgOverTime)
end
end)
It looks like you are making some kind of damage due a Variable. I do not recommend doing it by a Changed function, you can directly make a loop which goes everytime or in the changed function you could just instead of doing what you did, do this:
This worked very well, albeit the loop just wants to get that last bit of damage in.
I could conteract that by instead of making the loop depend on the value, just put an if statement with a break
Sorry, ignore the first part. Don’t do a loop, it depends on the system.
About the second part though.
while BleedVal.Value == val do
end
As you can clearly see, it checks if the BleedVal.Value is still the same like the one when it got changed. The Changed function only sets it value once and never again, as it is a loops once it changed and can’t change it value again.