I have a swim script and I was just wondering if someone could help improve it. All I really need is for the player to have a certain speed (16) while in the water the can’t be changed. I have a sprint script and you can toggle it in the water which I don’t want so if someone could help I would appreciate it.
--Services{
local replicatedStorage = game:GetService("ReplicatedStorage")
local inputService = game:GetService("UserInputService")
local context = game:GetService("ContextActionService")
local playerService = game:GetService("Players")
local runService = game:GetService("RunService")
local lighting = game:GetService("Lighting")
--}
--Vars{
local player = playerService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local diveCorrection = lighting:WaitForChild("DiveCorrection")
local humanoid = character:WaitForChild("Humanoid")
local diveBlur = lighting:WaitForChild("DiveBlur")
local seaValue = script:WaitForChild("SeaValue")
local sea = seaValue.Value
local ocean = sea:WaitForChild("Ocean")
local sand = sea:WaitForChild("Sand")
--}
--LocalVars{
local swimPosition = nil
local surfacing = false
local isDiving = false
local swimming = false
local canJump = false
local isDive = false
local swimTrack = humanoid:LoadAnimation(game.ReplicatedFirst.Animations.Swim)
--}
--Tables{
local oceanSetting = {
["LastCheck"] = DateTime.now().UnixTimestamp;
["TimerChange"] = 25;
["CurrentCount"] = 1;
}
local textureList = {
"http://www.roblox.com/asset/?id=251911331";
"http://www.roblox.com/asset/?id=251911339";
"http://www.roblox.com/asset/?id=251911347";
"http://www.roblox.com/asset/?id=251911363";
"http://www.roblox.com/asset/?id=251911369";
"http://www.roblox.com/asset/?id=251911379";
"http://www.roblox.com/asset/?id=251911392";
"http://www.roblox.com/asset/?id=251911407";
"http://www.roblox.com/asset/?id=251911419";
"http://www.roblox.com/asset/?id=251911429";
"http://www.roblox.com/asset/?id=251911442";
"http://www.roblox.com/asset/?id=251911454";
"http://www.roblox.com/asset/?id=251911472";
"http://www.roblox.com/asset/?id=251911481";
"http://www.roblox.com/asset/?id=251911490";
"http://www.roblox.com/asset/?id=251911502";
"http://www.roblox.com/asset/?id=251911515";
"http://www.roblox.com/asset/?id=251911532";
"http://www.roblox.com/asset/?id=251915177";
"http://www.roblox.com/asset/?id=251911587";
"http://www.roblox.com/asset/?id=251911594";
"http://www.roblox.com/asset/?id=251911605";
"http://www.roblox.com/asset/?id=251911616";
"http://www.roblox.com/asset/?id=251911630";
"http://www.roblox.com/asset/?id=251911639";
}
--}
player.CharacterAdded:Connect(function(char)
character = char
humanoidRootPart = char:WaitForChild("HumanoidRootPart")
humanoid = char:WaitForChild("Humanoid")
swimPosition = nil
surfacing = false
isDiving = false
swimming = false
canJump = false
isDive = false
swimTrack = humanoid:LoadAnimation(game.ReplicatedFirst.Animations.Swim)
ocean.Position = Vector3.new(humanoidRootPart.Position.X, ocean.Position.Y, humanoidRootPart.Position.Z)
sand.Position = Vector3.new(humanoidRootPart.Position.X, sand.Position.Y, humanoidRootPart.Position.Z)
end)
humanoid.Destroying:Connect(function()
swimPosition = nil
surfacing = false
isDiving = false
swimming = false
canJump = false
isDive = false
swimTrack:Stop()
end)
ocean.Touched:Connect(function(otherPart)
if swimming == true then return end
if otherPart.Parent == character and otherPart == character.PrimaryPart then
swimming = true
game.ReplicatedStorage.Bindables.PlayEffect:Fire("Splash", humanoidRootPart.CFrame, ocean.Position.Y + 7)
swimPosition = Instance.new("BodyPosition")
swimPosition.MaxForce = Vector3.new(0, 100000, 0)
swimPosition.Position = Vector3.new(0, ocean.Position.Y + 7.5, 0)
runService.RenderStepped:Wait()
task.wait(.05)
swimTrack:Play()
swimPosition.Parent = humanoidRootPart
task.wait(.25)
canJump = true
end
end)
inputService.JumpRequest:Connect(function()
if swimPosition ~= nil and swimming and canJump and isDiving == false and isDive == false and surfacing == false then
canJump = false
swimPosition.Position = swimPosition.Position + Vector3.new(0, 25, 0)
swimTrack:Stop()
task.wait(.5)
swimPosition:Destroy()
swimming = false
end
end)
runService.RenderStepped:Connect(function()
runService.RenderStepped:Wait()
if character ~= nil then
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart ~= nil then
local distCheck = (character:GetPivot().Position - ocean.Position).Magnitude
if distCheck >= 750 then
ocean.Position = Vector3.new(humanoidRootPart.Position.X, ocean.Position.Y, humanoidRootPart.Position.Z)
sand.Position = Vector3.new(humanoidRootPart.Position.X, sand.Position.Y, humanoidRootPart.Position.Z)
end
end
end
local camera = workspace.CurrentCamera
if camera.CFrame.Y < ocean.Position.Y + 8 then
diveBlur.Enabled = true
diveCorrection.Enabled = true
else
diveBlur.Enabled = false
diveCorrection.Enabled = false
end
end)