What do I want to achieve? I want the water to damage the player every second.
What is the issue? Using the Touched event, will only hurt me if a new body part comes into the water.
What solutions have you tried so far? I tried using Region3, but it was too confusing. If you think Region3 can help, please tell me.
I have a script here using Region3 (I used Alvinblox’s tutorial):
local char = script.Parent
local water = workspace.Ocean.Water
local found = false
char.HumanoidRootPart.Changed:Connect(function(prop)
if char.Humanoid.Health > 0 then
if tostring(prop) ~= 'NetworkOwnerV3' then
print('Still running [1]')
local v = char.HumanoidRootPart[prop]
if v == char.HumanoidRootPart.Position then
print('Still running [2]')
local region = Region3.new(water.Position - (water.Size / 2), water.Position + (water.Size / 2))
found = false
for i, v in pairs(workspace:FindPartsInRegion3WithWhiteList(region, char:GetDescendants())) do
print('Still running [3]')
if v:FindFirstAncestor(char:getPlayerFromCharacter().Name) then
print('Still running [4]')
found = true
break
else
print('Still running [5]')
found = false
end
print('Still running [6]')
end
if found then
print('Still running [7]')
char.Humanoid.WalkSpeed = 12
char.Humanoid.JumpPower = 0
char.Humanoid.Health -= 5
else
print('Still running [8]')
char.Humanoid.WalkSpeed = 16
char.Humanoid.JumpPower = 50
end
print('Still running [9]')
end
end
end
end)
I keep printing “Still running” to see if it stopped at some point. There are no errors and the output says the same thing and stays the same.
Output:
Still running [1] (x2) - Server - DeadlyWater:8
Still running [2] - Server - DeadlyWater:13
Still running [8] - Server - DeadlyWater:44
Still running [9] - Server - DeadlyWater:50
Thank you in advance! (I’ll check this on Tuesday, it’s night time right now)
You can use .Touched and put a bool value inside of a player that checks if they’ve touched it or not. (Just insert a new bool value in StarterCharacterScripts and name it whatever you want)
WaterPart.Touched:Connect(function(Object)
if Object.Parent:FindFirstChild:("Humanoid") then
local Character = Object.Parent
if Character.WaterTouched.Value == true then return end -- this is the value
Character.WaterTouched.Value = true
Character.Humanoid:TakeDamage(10) -- your amount of damage here
wait(1)
Character.WaterTouched.Value = false
end
end)
It works great! Thanks! Can you tell me how I can slow the player down though and make them unable to jump? When they get out of the water they can jump and walk/run perfectly fine. One problem. The player can just freeze in the water standing still and regain health. In my game, I don’t want players to swim all the way to other islands. I want them to buy boats.
Why not use a variation of a simple kill script in a Transparent, CanCollide False, CanTouch True, Part (or Parts) that are the same size as the water?
This will kill on touch, but if you put a loop in you could make it slowly decrease the player’s Health.
local Kill = script.Parent
local function PlayerTouched(Part)
local Parent = Part.Parent
if game.Players:GetPlayerFromCharacter(Parent) then
Parent.Humanoid.Health = 0
end
end
Kill.Touched:connect(PlayerTouched)
Maybe you could use this with bodyvelocity or the values inside the humanoid
Under the “Character.Humanoid:TakeDamage()” you could do:
Humanoid
Character.Humanoid.WalkSpeed = 5 -- how much you want to reduce, starts at 16
Character.Humanoid.JumpPower = 0 -- starts at 50
wait(1)
Character.Humanoid.WalkSpeed = 16
Character.Humanoid.JumpPower = 50
Character.WaterTouched.Value = false
BodyVelocity
local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.Parent = Character.HumanoidRootPart
BodyVelocity.MaxForce = Vector3.new(8000,8000,8000)
BodyVelocity.Velocity = Vector3.new(0, 0.1, 0) -- makes the player go a tenth of a stud higher every time they touch the water, but makes them unable to move (i think lol)
wait(1)
BodyVelocity:Destroy
Character.WaterTouched.Value = false
My dearest apologies if there are any mistakes or errors in the script, I just woke up.
With Body Velocity, I can still jump and then I just fly into the air without moving. In my first reply, I said I don’t want the player to stand still and regenerate all their health back that the water just damaged them.
Ah apologies, I probably skipped over that part while reading. Maybe you could make them shake a little while they’re in the water, that should trigger the .Touched event.
Just put a tiny bit of a force that constantly moves the player a tiny bit in one direction, then reverses in the other direction.
Just enough to cause movement in relation to whatever is taking the health, whether it’s in your script or a transparent ‘kill’ brick with the health decreasing script put in it Not enough to be noticeable in game.