The title says it all
local Sea = workspace:WaitForChild("Sea")
local RS = game:GetService("RunService")
local Character = script.Parent
local plr = game.Players.LocalPlayer
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local Swim
local function PlayersInPart(Part)
local Parts = workspace:GetPartsInPart(Part)
local Players = {}
for i, v in pairs(Parts) do
local Player = game.Players:GetPlayerFromCharacter(v.Parent)
if v.Name == "LeftUpperArm" then
if Player then
table.insert(Players, Player)
end
end
end
return Players
end
RS.RenderStepped:Connect (function ()
local PlayersInWater = PlayersInPart(Sea)
if table.find(PlayersInWater, plr) then
if Root.Position.Y < Sea.Position.Y - Root.Position.Y / 2 then
if not Swim then
Swim = Instance.new("BodyVelocity")
Swim.Parent = Root
end
Humanoid.JumpPower = 30
Humanoid.WalkSpeed = 16
Swim.Velocity = Humanoid.MoveDirection * Humanoid.WalkSpeed
if Humanoid:GetState() ~= Enum.HumanoidStateType.Swimming then
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
Humanoid:ChangeState(Enum.HumanoidStateType.Swimming)
end
elseif Swim and Root.Position.Y < Sea.Position.Y then
Swim.Velocity = Humanoid.MoveDirection * Humanoid.WalkSpeed
elseif Swim then
Swim:Destroy()
Swim = nil
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
end
else
if Swim ~= nil then
Swim:Destroy()
Swim = nil
Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
end
end
end)