Advertisement
IHATEMICROWAVEOVEN

konnichiwater EX

May 20th, 2022
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. local WaterDict = game.Workspace.WaterFolder:GetChildren()
  2. local Torso = script.Parent:WaitForChild("Torso")
  3. local ShouldUpdateMass = true
  4. local Mass = 0
  5. local WorldGravity = 196.2
  6. local WaterGravity = WorldGravity / 4
  7. local GravityForce = Instance.new("BodyForce", Torso)
  8. local UnderWaterEffect = game:GetService("Lighting"):WaitForChild("UnderWaterEffect")
  9. local UnderWaterSwampEffect = game:GetService("Lighting"):WaitForChild("UnderWaterSwampEffect")
  10. local UnderLavaEffect = game:GetService("Lighting"):WaitForChild("UnderLavaEffect")
  11. local UnderWaterSoundEffects = {}
  12. for _, Effect in pairs(game:GetService("SoundService"):WaitForChild("Music"):GetChildren()) do
  13. if Effect.Name == "UnderWaterEffect" then
  14. table.insert(UnderWaterSoundEffects, Effect)
  15. end
  16. end
  17. local Camera = game:GetService("Workspace").CurrentCamera
  18. function GetCharacterMass()
  19. local CharacterMass = 0
  20. for _, Inst in pairs(script.Parent:GetDescendants()) do
  21. if Inst:IsA("BasePart") then
  22. CharacterMass = CharacterMass + Inst:GetMass()
  23. end
  24. end
  25. return CharacterMass
  26. end
  27.  
  28. local thresholds = {}
  29.  
  30. for _, i in pairs(WaterDict) do
  31. local pos = i.Position
  32. local size = i.Size
  33. table.insert(thresholds, {[i] = {
  34. pos.X-(size.X/2), pos.X+(size.X/2),
  35. pos.Y-(size.Y/2), pos.Y+(size.Y/2),
  36. pos.Z-(size.Z/2), pos.Z+(size.Z/2),
  37. i.Biome.Value
  38. }})
  39. -- store these precalculated borders for every part
  40. -- [part] = {BOTX, TOPX, BOTY, TOPY, BOTZ, TOPZ, BIOME}
  41. -- this is identical to the old script except these aren't recalculated every frame lol
  42. end
  43.  
  44.  
  45. function IsUnderWater(X, Y, Z)
  46. if Y <= 17.5 and Y >= -43 then return true, "Normal" end
  47. for n, data in pairs(thresholds) do -- n = NUM, data = TABLE
  48. for p, i in pairs(data) do -- p = PART, i = TABLE (BOTX, TOPX etc)
  49. if X>i[1] and X<i[2] and Y>i[3] and Y<i[4] and Z>i[5] and Z<i[6] then
  50. return true, i[7]
  51. end
  52. end
  53. end
  54. return false, "None"
  55. end
  56. game:GetService("RunService").Heartbeat:Connect(function()
  57. if ShouldUpdateMass then Mass = GetCharacterMass() end
  58. local UnderWater, WaterType = IsUnderWater(Torso.Position.X, Torso.Position.Y, Torso.Position.Z)
  59. GravityForce.Force = Vector3.new(0, UnderWater and ((Mass * WorldGravity) - (Mass * WaterGravity)) or 0, 0)
  60. for _, Effect in pairs(UnderWaterSoundEffects) do
  61. Effect.Enabled = UnderWater
  62. end
  63. end)
  64. game:GetService("RunService").RenderStepped:Connect(function()
  65. local UnderWater, WaterType = IsUnderWater(Camera.CFrame.X, Camera.CFrame.Y, Camera.CFrame.Z)
  66. UnderLavaEffect.Enabled = UnderWater and WaterType == "Lava"
  67. UnderWaterEffect.Enabled = UnderWater and WaterType == "Normal"
  68. UnderWaterSwampEffect.Enabled = UnderWater and WaterType == "Swamp"
  69. end)
  70. script.Parent.DescendantAdded:Connect(function() ShouldUpdateMass = true end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement