Hello,
I’m trying to achieve a way that players will get damage if their value is higher than 75 and lower than 25.
I’ve tried using coroutine and switching the position of the loop and this is what I’ve came so far. However, it not printing true for some reason. I’ve ran out of idea as this point so any suggestions would be a blessing.
local maxValue = 100
local ColdEffect = game:GetService("ReplicatedStorage").Assets:WaitForChild("ColdEffect")
local HotEffect = game:GetService("ReplicatedStorage").Assets:WaitForChild("HotEffect")
local NewColdEffect
local NewHotEffect
game.Players.PlayerAdded:Connect(function(player)
local data = Instance.new("Folder")
data.Name = "Data"
data.Parent = player
local temp = Instance.new("NumberValue")
temp.Value = 50
temp.Name = "Temp"
temp.Parent = data
task.wait(1)
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local tempData = player.Data:WaitForChild("Temp")
local damagePerSecond = 50
local willLoop = false
player.Data:WaitForChild("Temp").Changed:Connect(function()
math.round(tempData.Value)
if tempData.Value >= 25 or tempData.Value <= 75 then
willLoop = false
print(willLoop, tempData.Value)
else
print("huh")
willLoop = true
if character.HumanoidRootPart:FindFirstChild("FlameHit") then
NewHotEffect:Destroy()
elseif character.HumanoidRootPart:FindFirstChild("WaterHit") then
NewColdEffect:Destroy()
end
end
if tempData.Value < 0 then
tempData.Value = 0
end
if tempData.Value > maxValue then
tempData.Value = 100
end
end)
while willLoop == true do
if tempData.Value <= 25 then
NewHotEffect = HotEffect:Clone()
NewHotEffect:Clone()
NewHotEffect.Parent = character:WaitForChild("HumanoidRootPart")
NewHotEffect.CFrame = character:WaitForChild("HumanoidRootPart").CFrame
local Weld = Instance.new("Weld")
Weld.Parent = NewHotEffect
Weld.Part0 = NewHotEffect
Weld.Part1 = character:WaitForChild("HumanoidRootPart")
Weld.C0 = CFrame.new(0, 0, 0)
while tempData.Value <= 25 do
task.wait(1)
humanoid:TakeDamage(damagePerSecond)
if tempData.Value >= 25 then
break
end
end
elseif tempData.Value >= 75 then
NewColdEffect = ColdEffect:Clone()
NewColdEffect:Clone()
NewColdEffect.Parent = character:WaitForChild("HumanoidRootPart")
NewColdEffect.CFrame = character:WaitForChild("HumanoidRootPart").CFrame
local Weld = Instance.new("Weld")
Weld.Parent = NewColdEffect
Weld.Part0 = NewColdEffect
Weld.Part1 = character:WaitForChild("HumanoidRootPart")
Weld.C0 = CFrame.new(0, 0, 0)
while tempData.Value >= 75 do
task.wait(1)
humanoid:TakeDamage(damagePerSecond)
if tempData.Value <= 75 then
break
end
end
end
end
humanoid.Died:Connect(function()
task.wait(game.Players.RespawnTime)
player.Data.Temp.Value = 50
end)
end)
Thank you!