I’ve been experiencing some issues with this script, basically, i want the player to die if he touches the water, currently, i use this script:
--DEV NOTE: Script is not optimized, fix it ASAP
--Begin--
local Humanoid = script.Parent.Humanoid
while true do
local Material = Humanoid.FloorMaterial
if Material == Enum.Material.CrackedLava or Humanoid:GetState() == Enum.HumanoidStateType.Swimming then
Humanoid:TakeDamage(100)
end
wait(1/60)
end
However, sometimes if the player quickly jumps on the water death is avoided, and i don’t find what causes it.
--DEV NOTE: Script is not optimized, fix it ASAP
--Begin--
local Humanoid = script.Parent.Humanoid
while true do
local Material = Humanoid.FloorMaterial
if Material == Enum.Material.CrackedLava or Humanoid:GetState() == Enum.HumanoidStateType.Swimming or Material == Enum.Material.Water then
Humanoid:TakeDamage(100)
end
wait(0.1)
end
what i think the problem is, is the default animation of jumping lifts the character up like a stud or two. When someone holds down space, the animation is constantly playing, which makes them float for a second and not actually touch the ground.
what you have to do is make the water part cancollide false so that the player can actually touch it and the jump animation doesnt get in the way
Cast a ray down with Terrain in the whitelist to check if the player is in water if the state isn’t “Swimming”. Also, you should connect these kinds of functions to Heartbeat.
I’m not using PARTS, i’m using TerrainWater and as such, i’m not trying to look for PARTS, i’m looking for TerrainWater. Is there any way to check for TerrainWater?
I’d try maybe using StateChanged to detect the water instead.
(firefox isnt letting me put tabs sorry)
local Humanoid = script.Parent.Humanoid
Humanoid.StateChanged:Connect(function(_,new)
if new == Enum.HumanoidStateType.Swimming then
Humanoid:TakeDamage(100)
end
end)
while true do
local Material = Humanoid.FloorMaterial
if Material == Enum.Material.CrackedLava then
Humanoid:TakeDamage(100)
end
wait(1/60)
end
also if you want to make sure they die try making them takedamage for their maxhealth