I’ve been trying for almost a week now to make a fly script but with my lack of coding knowledge I still don’t even know how to even get started on this. I’m using the ZonePlus module for this to make it so that the player “Swims” using LinearVelocity. The issue I keep getting is the fact that it never ends up the way I want it to not to mention the fact that all the other fly script tutorials out there are outdated. My script usually goes along the lines of
local ZoneModule = require(game.ReplicatedStorage.Zone)
local Container = game.Workspace.WaterFolder:WaitForChild("Model").Ocean
local Zone = ZoneModule.new(Container)
Zone.playerEntered:Connect(function()
- Swim/Flight Code here
end)
Zone.playerExited:Connect(function()
- Swim/Flight Code Here
end)
The swimming I’m trying to make is similar to that of the swimming mechanics in the Roblox game “pressure” (Cough cough Zeal). I’ve asked the owner how he made it but all I was able to get was the fact that he was making the player fly in the water parts as an illusion to make it seem like the player is swimming. I Prefer this method over regular Roblox swimming because it’s smoother, it’s better, and it’s easier for me when it comes to coding since I’m really not a fan of terrain related coding.
local ZoneModule = require(game.ReplicatedStorage.Zone)
local Container = game.Workspace.WaterFolder:WaitForChild("Model").Ocean
local Zone = ZoneModule.new(Container)
local function enableFlight(player)
local character = player.Character
if character then
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.Name = "SwimVelocity"
linearVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
linearVelocity.Attachment0 = character.HumanoidRootPart:FindFirstChild("RootAttachment")
linearVelocity.Parent = character.HumanoidRootPart
end
end
local function disableFlight(player)
local character = player.Character
if character then
local linearVelocity = character.HumanoidRootPart:FindFirstChild("SwimVelocity")
if linearVelocity then
linearVelocity:Destroy()
end
end
end
Zone.playerEntered:Connect(function(player)
enableFlight(player)
end)
Zone.playerExited:Connect(function(player)
disableFlight(player)
end)
-- Adjustments: You can adjust the MaxForce property of the LinearVelocity to control how strong the swimming effect is. Ensure the attachments are correctly set up on the player's HumanoidRootPart. This script assumes the player character has a HumanoidRootPart with a RootAttachment.
It comes up with an error “value of type Vector3 cannot be converted to a number” but even then thank you very much for the help because this helped me figure out how to use LV in scripting!
Oh yes it was the error value its because of how attachments might be setup.
It also creates one if it doesn’t find it
local ZoneModule = require(game.ReplicatedStorage.Zone)
local Container = game.Workspace.WaterFolder:WaitForChild("Model").Ocean
local Zone = ZoneModule.new(Container)
local function ensureRootAttachment(character)
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart and not humanoidRootPart:FindFirstChild("RootAttachment") then
local rootAttachment = Instance.new("Attachment")
rootAttachment.Name = "RootAttachment"
rootAttachment.Parent = humanoidRootPart
end
end
local function enableFlight(player)
local character = player.Character
if character then
ensureRootAttachment(character)
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.Name = "SwimVelocity"
linearVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
linearVelocity.Attachment0 = character.HumanoidRootPart:FindFirstChild("RootAttachment")
linearVelocity.Parent = character.HumanoidRootPart
end
end
local function disableFlight(player)
local character = player.Character
if character then
local linearVelocity = character.HumanoidRootPart:FindFirstChild("SwimVelocity")
if linearVelocity then
linearVelocity:Destroy()
end
end
end
Zone.playerEntered:Connect(function(player)
enableFlight(player)
end)
Zone.playerExited:Connect(function(player)
disableFlight(player)
end)
This one seems to have the same error on the same line as the “linearVelocity.MaxForce = Vector3.new(4000, 4000, 4000)”. I’m not sure why it keeps on giving that error since it worked like that for me when I used a bodyvelocity before.
local ZoneModule = require(game.ReplicatedStorage.Zone)
local Container = game.Workspace.WaterFolder:WaitForChild("Model").Ocean
local Zone = ZoneModule.new(Container)
local function ensureRootAttachment(character)
local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart and not humanoidRootPart:FindFirstChild("RootAttachment") then
local rootAttachment = Instance.new("Attachment")
rootAttachment.Name = "RootAttachment"
rootAttachment.Parent = humanoidRootPart
end
end
local function enableFlight(player)
local character = player.Character
if character then
ensureRootAttachment(character)
local linearVelocity = Instance.new("LinearVelocity")
linearVelocity.Name = "SwimVelocity"
linearVelocity.MaxForce = 4000
linearVelocity.VectorVelocity = Vector3.new(4000,4000,4000) -- This fixed it
linearVelocity.Attachment0 = character.HumanoidRootPart:FindFirstChild("RootAttachment")
linearVelocity.Parent = character.HumanoidRootPart
end
end
local function disableFlight(player)
local character = player.Character
if character then
local linearVelocity = character.HumanoidRootPart:FindFirstChild("SwimVelocity")
if linearVelocity then
linearVelocity:Destroy()
end
end
end
Zone.playerEntered:Connect(function(player)
enableFlight(player)
end)
Zone.playerExited:Connect(function(player)
disableFlight(player)
end)
Found what was causing the problem! Now I just need to figure how to make it move with the direction the player is facing.