Hello! I am making a roblox game like subnautica, though we are stuck on one thing. I need help with a breathing script, like player can be underwater for 10 sec, after that they get damaged 10 hp each extra second. Anyone knows how to make something like this? Thanks!
COMMUNITY QUESTION
Stuck on a script: In need of breathing script. Anyone can help me?
1 answer
So you can make a touched event for terrain, it will look a little bit like (not writing real lua code because you haven't attempted it yet):
water = 2048 -- the material code for water
int underwater = 0--have it count up for every second under the water
if player touches terrain and terrain's material value is 2048 then
if underwater > 10 then
do damage to the player's humanoid
wait(1)--make it wait a second before checking again
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
When players touch the water and 10 seconds have passed, use a while loop to keep doing damage do them and elseif touchended, break the loop
Thank you! THough, can it be a water generated by terrain? Or do I need to place a script-block? ( Block that is transparent, cannot collide ) in the water?