Advertisement
IHATEMICROWAVEOVEN

konnichiwater

Nov 28th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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. function IsUnderWater(X, Y, Z)
  28. if Y <= 17.5 and Y >= -43 then return true, "Normal" end -- ocean btw
  29. for _, i in pairs(WaterDict) do
  30. if X>i.Position.X-(i.Size.X/2) and X<i.Position.X+(i.Size.X/2) and Y>i.Position.Y-(i.Size.Y/2) and Y<i.Position.Y+(i.Size.Y/2) and Z>i.Position.Z-(i.Size.Z/2) and Z<i.Position.Z+(i.Size.Z/2) then
  31. return true, i.Biome.Value
  32. end
  33. end
  34. return false, "None"
  35. end
  36. game:GetService("RunService").Heartbeat:Connect(function()
  37. if ShouldUpdateMass then Mass = GetCharacterMass() end
  38. local UnderWater, WaterType = IsUnderWater(Torso.Position.X, Torso.Position.Y, Torso.Position.Z)
  39. GravityForce.Force = Vector3.new(0, UnderWater and ((Mass * WorldGravity) - (Mass * WaterGravity)) or 0, 0)
  40. for _, Effect in pairs(UnderWaterSoundEffects) do
  41. Effect.Enabled = UnderWater
  42. end
  43. end)
  44. game:GetService("RunService").RenderStepped:Connect(function()
  45. local UnderWater, WaterType = IsUnderWater(Camera.CFrame.X, Camera.CFrame.Y, Camera.CFrame.Z)
  46. UnderLavaEffect.Enabled = UnderWater and WaterType == "Lava"
  47. UnderWaterEffect.Enabled = UnderWater and WaterType == "Normal"
  48. UnderWaterSwampEffect.Enabled = UnderWater and WaterType == "Swamp"
  49. end)
  50. script.Parent.DescendantAdded:Connect(function() ShouldUpdateMass = true end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement