I want to achieve it after the player has been in the water for 30 seconds then it starts to drown.
The drowning happens immediately.
I have tried to look for solutions all over the dev forum. I found this script because it was marked as a solution but I cannot time it to drown after 30 seconds. I have tried but here is the original script.
local Character = script.Parent
local Humanoid = Character.Humanoid
local Swimming = false
Humanoid.StateChanged:Connect(function (oldState, newState)
if newState == Enum.HumanoidStateType.Swimming then
print("Swim")
Swimming = true
elseif oldState == Enum.HumanoidStateType.Swimming and newState ~= Enum.HumanoidStateType.Jumping then
print("No swim")
Swimming = false
elseif oldState ~= Enum.HumanoidStateType.Swimming and oldState ~= newState then
print("No swim")
Swimming = false
end
while Swimming do
Humanoid:TakeDamage(5)
if Swimming then
wait(1)
end
end
end)
You should be replacing that with the line I suggested. It’s essentially the same as the previous line, however this new one has different numbers as the argument.
Oh, you want to drown the player immediately after 30 seconds? Then something like this should do the trick:
for i = 1, 30 do
if not Swimming then return end
end
Humanoid:TakeDamage(100)
This script will check every second for 30 seconds if the player is swimming. If it ever returns false, the code will stop. If it is able to finish counting to 30 without interuptions, the player will be killed.
Edit: Clarification, you’ll replace the while loop with this.
No, that would be a terrible idea. If you did that, it’d wait 30 seconds before every single chip of damage. Essentially, it would take minutes for the player to die.