Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine,math,string,table,game,Game,workspace,Workspace,delay,Delay,LoadLibrary,printidentity,Spawn,tick,time,version,Version,Wait,wait,PluginManager,crash__,LoadRobloxLibrary,settings,Stats,stats,UserSettings,Enum,Color3,BrickColor,Vector2,Vector3,Vector3int16,CFrame,UDim,UDim2,Ray,Axes,Faces,Instance,Region3,Region3int16=_G,_VERSION,assert,collectgarbage,dofile,error,getfenv,getmetatable,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,rawequal,rawget,rawset,select,setfenv,setmetatable,tonumber,tostring,type,unpack,xpcall,coroutine,math,string,table,game,Game,workspace,Workspace,delay,Delay,LoadLibrary,printidentity,Spawn,tick,time,version,Version,Wait,wait,PluginManager,crash__,LoadRobloxLibrary,settings,Stats,stats,UserSettings,Enum,Color3,BrickColor,Vector2,Vector3,Vector3int16,CFrame,UDim,UDim2,Ray,Axes,Faces,Instance,Region3,Region3int16
- math.randomseed(tick())
- local Players = Game:GetService('Players')
- local StarterPack = Game:GetService('StarterPack')
- local StarterGui = Game:GetService('StarterGui')
- local Lighting = Game:GetService('Lighting')
- local Debris = Game:GetService('Debris')
- local Teams = Game:GetService('Teams')
- local BadgeService = Game:GetService('BadgeService')
- local InsertService = Game:GetService('InsertService')
- local Terrain = Workspace.Terrain
- local VerifyArg
- local function IsA(value, data_type)
- data_type = VerifyArg(data_type, 'string', "data_type")
- if type(value) == data_type then return true end -- Lua types
- if pcall(function() assert(Game.IsA(value, data_type)) end) then return true end -- Instance types
- if pcall(function() assert(Enum[data_type]) end) then -- Enum types
- for _, enum in next, Enum[data_type]:GetEnumItems() do
- if value == enum then
- return true
- end
- end
- elseif pcall(Enum.Material.GetEnumItems, value) then
- for _, enum in next, value:GetEnumItems() do
- if value == enum then
- return true
- end
- end
- end
- if data_type == 'Color3' and pcall(function() Instance.new('Color3Value').Value = value end) then return true -- Color3
- elseif data_type == 'BrickColor' and pcall(function() Instance.new('BrickColorValue').Value = value end) then return true -- BrickColor
- elseif data_type == 'Vector2' and pcall(function() return Vector2.new() + value end) then return true -- Vector2
- elseif data_type == 'Vector3' and pcall(function() Instance.new('Vector3Value').Value = value end) then return true -- Vector3
- elseif (data_type == 'CFrame' or data_type == 'CoordinateFrame') and pcall(function() Instance.new('CFrameValue').Value = value end) then return true -- CFrame
- elseif data_type == 'UDim' and pcall(function() return UDim.new() + value end) then return true -- UDim
- elseif data_type == 'UDim2' and pcall(function() Instance.new('Frame').Position = value end) then return true -- UDim2
- elseif data_type == 'Ray' and pcall(function() Ray.new(Vector3.new(), Vector3.new()).Distance(value, Vector3.new()) end) then return true -- Ray
- elseif data_type == 'Axes' and pcall(function() Instance.new('ArcHandles').Axes = value end) then return true -- Axes
- elseif data_type == 'Faces' and pcall(function() Instance.new('Handles').Faces = value end) then return true -- Faces
- elseif data_type == 'Enum' and pcall(Enum.Material.GetEnumItems, value) then return true -- Enum
- elseif data_type == 'RBXScriptSignal' then
- local _, connection = pcall(function() return Game.AllowedGearTypeChanged.connect(value) end)
- if _ and connection then
- connection:disconnect()
- return true
- end
- end
- return false
- end
- local function CppIsA(value, data_type)
- data_type = VerifyArg(data_type, 'string', "data_type")
- if data_type == 'int' then
- if pcall(function() Instance.new('IntValue').Value = value end) then
- return true
- end
- elseif data_type == 'double' then
- if pcall(function() Instance.new('NumberValue').Value = value end) then
- return true
- end
- elseif data_type == 'bool' then
- if pcall(function() Instance.new('BoolValue').Value = value end) then
- return true
- end
- elseif data_type == 'string' then
- if pcall(function() Instance.new('StringValue').Value = value end) then
- return true
- end
- elseif data_type == 'float' then
- if pcall(function() Instance.new('ClickDetector').MaxActivationDistance = value end) then
- return true
- end
- end
- return false
- end
- local function GetType(value)
- if IsA(value, 'Instance') then return value.ClassName
- elseif IsA(value, 'Enum') then return 'Enum'
- elseif IsA(value, 'Color3') then return 'Color3'
- elseif IsA(value, 'BrickColor') then return 'BrickColor'
- elseif IsA(value, 'Vector2') then return 'Vector2'
- elseif IsA(value, 'Vector3') then return 'Vector3'
- elseif IsA(value, 'CFrame') then return 'CFrame'
- elseif IsA(value, 'UDim') then return 'UDim'
- elseif IsA(value, 'UDim2') then return 'UDim2'
- elseif IsA(value, 'Ray') then return 'Ray'
- elseif IsA(value, 'Axes') then return 'Axes'
- elseif IsA(value, 'Faces') then return 'Faces'
- elseif IsA(value, 'RBXScriptSignal') then return 'RBXScriptSignal'
- else return type(value)
- end
- end
- function VerifyArg(value, data_type, arg_name, optional)
- if type(data_type) ~= 'string' then error("bad 'data_type' argument (string expected, got " .. GetType(data_type) .. ")", 2) end
- if type(arg_name) ~= 'string' then error("bad 'arg_name' argument (string expected, got " .. GetType(arg_name) .. ")") end
- if optional and value == nil then
- return value
- elseif type(value) == data_type then
- return value
- elseif IsA(value, data_type) or CppIsA(value, data_type) then
- return value
- elseif data_type == 'number' and tonumber(value) then
- return tonumber(value)
- elseif data_type == 'string' and type(value) == 'number' then
- return tostring(value)
- else
- error("bad '" .. arg_name .. "'" .. (optional and " optional" or "") .. " argument (" .. data_type .. " expected, got " .. GetType(value) .. ")", 3)
- end
- end
- local function Modify(instance, t)
- instance = VerifyArg(instance, 'Instance', "instance")
- t = VerifyArg(t, 'table', "t")
- for key, value in next, t do
- if type(key) == 'number' then
- value.Parent = instance
- else
- instance[key] = value
- end
- end
- return instance
- end
- local function WaitForChild(Parent, Name)
- Parent = VerifyArg(Parent, 'Instance', "Parent")
- Name = VerifyArg(Name, 'string', "Name")
- local Item = Parent:FindFirstChild(Name)
- if not Item then
- repeat wait(0) print("Waiting for "..Name) Item = Parent:FindFirstChild(Name) until Item
- end
- return Item;
- end
- local function CallOnChildren(instance, func)
- instance = VerifyArg(instance, 'Instance', "instance")
- func = VerifyArg(func, 'function', "func")
- func(instance)
- for _, child in next, instance:GetChildren() do
- CallOnChildren(child, func)
- end
- end
- local function GetNearestParent(instance, class_name)
- instance = VerifyArg(instance, 'Instance', "instance")
- class_name = VerifyArg(class_name, 'string', "class_name")
- local ancestor = instance
- repeat
- ancestor = ancestor.Parent
- if ancestor == nil then
- return nil
- end
- until ancestor:IsA(class_name)
- return ancestor
- end
- local function GetCharacter(descendant)
- descendant = VerifyArg(descendant, 'Instance', "descendant")
- local character = descendant
- repeat
- if character.Parent then
- character = character.Parent
- else
- return nil
- end
- until Players:GetPlayerFromCharacter(character)
- return character, Players:GetPlayerFromCharacter(character)
- end
- -- Variables --
- local ParentNamesNoDetect = {Water = true; Bodykit = true; Projectiles = true; Water = true; ["!Water"] = true; Wake = true;}
- local ChildrenParentNoDetect = {"Humanoid"}
- local NamesNoDetect = {Wake = true;}
- local WaterLevel = 3000
- local ShipGui = WaitForChild(script, "ShipGui")
- local function RoundNumber(Number, Divider)
- Divider = Divider or 1
- return (math.floor((Number/Divider)+5)*Divider)
- end
- local function ClampNumber(Number, High, Low)
- if Number > High then
- return High;
- elseif Number < Low then
- return Low;
- end
- return Number;
- end
- local function MPStoKPS(MPS) -- Meters per a econd to Kilometers per a second
- return MPS * 3.6
- end
- local function SetupBoat(Boat, VehicleSeat, Configuration)
- --local Boat = script.Parent
- --local VehicleSeat = WaitForChild(Boat, "VehicleSeat")
- --local Base = WaitForChild(Boat, "Base")
- local ShipHealth = WaitForChild(VehicleSeat, "ShipHealth")
- local EngineSound = WaitForChild(VehicleSeat, "EngineSound")
- local BodyGyro = WaitForChild(VehicleSeat, "BodyGyro")
- local BodyVelocity = WaitForChild(VehicleSeat, "BodyVelocity")
- local BodyPosition = WaitForChild(VehicleSeat, "BodyPosition")
- local BodyAngularVelocity = WaitForChild(VehicleSeat, "BodyAngularVelocity")
- local Wake = Modify(Instance.new("Model", Boat), {Name="Wake"})
- ShipHealth.Changed:connect(function ()
- if ShipHealth.Value <= 1 then
- script.Parent.Disabled = true
- script.Parent.TurnSpeed = 0
- script.Parent.MaxSpeed = 0
- for i = BodyPosition.position.Y,-200,-0.1 do
- BodyPosition.position = Vector3.new(0, i, 0)
- wait()
- end
- script.Parent.Parent:Destroy()
- end
- end)
- local function GetCharacter(descendant)
- local character = descendant
- repeat
- if character.Parent then
- character = character.Parent
- else
- return nil
- end
- until Players:GetPlayerFromCharacter(character)
- return character, Players:GetPlayerFromCharacter(character)
- end
- local Config = Configuration
- Config.NeutralColor = BrickColor.new("Dark stone grey");
- local function Weld(Object, BaseObject)
- for _, Item in pairs(Object:GetChildren()) do
- if Item:IsA("BasePart") and Item ~= BaseObject and Item.Parent.Name ~= "Cannon" then
- local Weld = Modify(Instance.new("Weld", BaseObject), {
- Part0 = Item;
- Part1 = BaseObject;
- C0 = Item.CFrame:inverse()*CFrame.new(Item.Position);
- C1 = BaseObject.CFrame:inverse()*CFrame.new(Item.Position);
- })
- Item.Anchored = false
- --print("Welded "..Item:GetFullName())
- end
- Weld(Item, BaseObject)
- end
- end
- local function SetupTouch(Part)
- for _, Item in pairs(Part:GetChildren()) do
- if Item:IsA("BasePart") then
- local Name = string.lower(Item.Name)
- if Name == "hitdetect" or Name == "hitdetectrecolor" then
- Item.Touched:connect(function(NewPart)
- print("Touch")
- if NewPart and NewPart.Parent and NewPart:IsA("BasePart") and NewPart.CanCollide then
- if not (ParentNamesNoDetect[NewPart.Parent.Name] or NamesNoDetect[NewPart.Name]) then
- VehicleSeat.MaxSpeed = 0
- print("Stop")
- else
- local Valid = true
- for _, ChildName in pairs(ChildrenParentNoDetect) do
- if NewPart.Parent:FindFirstChild(ChildName) then
- Valid = false
- end
- end
- if Valid then
- print("Stop")
- VehicleSeat.MaxSpeed = 0
- end
- end
- end
- end)
- end
- end
- SetupTouch(Item)
- end
- end
- SetupTouch(Boat)
- Weld(Boat, VehicleSeat)
- VehicleSeat.ChildAdded:connect(function(Child)
- Spawn(function()
- if Child:IsA("Weld") then
- local Torso = Child.Part1
- if Torso and Torso:IsA("BasePart") then
- local Character, Player = GetCharacter(Torso)
- if Character and Player then
- for _, Item in pairs(Character:GetChildren()) do
- if Item:IsA("Model") and Item ~= Boat then
- Item:Destroy(); -- Remove all other boats.
- end
- end
- Boat.Parent = Character
- VehicleSeat.Anchored = false
- repeat wait(0) until Player:FindFirstChild("PlayerGui")
- local Gui = ShipGui:Clone()
- local MainFrame = WaitForChild(Gui, "MainFrame")
- local ShipName = WaitForChild(MainFrame, "ShipName")
- local ShipSpeed = WaitForChild(MainFrame, "ShipSpeed")
- local HealthRed = WaitForChild(MainFrame, "HealthRed")
- local HealthGreen = WaitForChild(HealthRed, "HealthGreen")
- ShipName.Text = Config.ShipName
- ShipSpeed.Text = "Shipspeed: 0.000 m/ps";
- Spawn(function()
- while Gui and Gui.Parent do
- wait(0.07)
- ShipSpeed.Text = "Shipspeed: "..RoundNumber(MPStoKPS(VehicleSeat.Velocity.magnitude/20), 0.001).." kph"
- HealthGreen.Size = UDim2.new(ShipHealth.Value/ShipHealth.MaxValue, 0, 1, 0)
- end
- print("Connection disconnected")
- end)
- Gui.Parent = Player.PlayerGui
- Child.AncestryChanged:connect(function(Child, Parent)
- if not Parent then
- if Gui then
- Gui:Destroy()
- end
- VehicleSeat.TurnSpeed = 0
- VehicleSeat.MaxSpeed = 0
- end
- end)
- end
- end
- end
- end)
- end)
- local RotationX, RotationY, RotationZ = VehicleSeat.CFrame:toEulerAnglesXYZ()
- BodyGyro.cframe = CFrame.Angles(0, RotationY, 0)
- Boat:MakeJoints()
- while true do
- local VehicleSeatThrottle = VehicleSeat.Throttle
- local VehicleSeatMaxSpeed = VehicleSeat.MaxSpeed
- local VehicleSeatSteer = VehicleSeat.Steer
- if VehicleSeat.Disabled == false then
- if VehicleSeatThrottle == 1 then
- if VehicleSeatMaxSpeed < Config.TopSpeed + 0.5 then
- VehicleSeat.MaxSpeed = VehicleSeatMaxSpeed + VehicleSeat.Torque
- end
- elseif VehicleSeatThrottle == -1 then
- if VehicleSeatMaxSpeed > -Config.TopSpeedReverse - 0.5 then
- VehicleSeat.MaxSpeed = VehicleSeatMaxSpeed - VehicleSeat.Torque
- end
- end
- if VehicleSeatSteer == 1 then
- if VehicleSeat.TurnSpeed > -Config.MaxTurn then
- VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed - Config.TurnSpeedAddition
- end
- elseif VehicleSeatSteer == -1 then
- if VehicleSeat.TurnSpeed < Config.MaxTurn then
- VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed + Config.TurnSpeedAddition
- end
- elseif VehicleSeatSteer == 0 then
- if VehicleSeat.TurnSpeed < 0 then
- VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed + Config.TurnSpeedAddition
- elseif VehicleSeat.TurnSpeed > 0 then
- VehicleSeat.TurnSpeed = VehicleSeat.TurnSpeed - Config.TurnSpeedAddition
- end
- if VehicleSeat.TurnSpeed <= Config.TurnStop and VehicleSeat.TurnSpeed >= -Config.TurnStop then
- VehicleSeat.TurnSpeed = 0
- end
- end
- end
- local Pitch = math.abs(VehicleSeat.MaxSpeed) / 10 + 2.5
- if VehicleSeatMaxSpeed > 0 then
- if Config.PlayEngineSound then
- EngineSound.Pitch = Pitch
- EngineSound:Play()
- end
- elseif VehicleSeatMaxSpeed < 0 then
- if Config.PlayEngineSound then
- EngineSound.Pitch = Pitch
- EngineSound:Play()
- end
- else
- EngineSound:Stop()
- end
- --BodyGyro.cframe = CFrame.Angles(0, (AngleY) + VehicleSeat.TurnSpeed, 0) * CFrame.new(Direction.p+Vector3.new(0,0,-1))
- --BodyGyro.cframe = VehicleSeat.CFrame * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0) --BodyGyro.cframe * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0) -- VehicleSeat.CFrame * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0)
- --BodyGyro.cframe = (VehicleSeat.CFrame.lookVector * CFrame.new(1, 0, 0)) * CFrame.Angles(0, VehicleSeat.TurnSpeed, 0)
- --print("Ship to be angled at "..((AngleY) + VehicleSeat.TurnSpeed)*(180/math.pi).." with AngleY (Actual) at "..(AngleY*(180/math.pi)).." with an increase of "..VehicleSeat.TurnSpeed*(180/math.pi))
- BodyAngularVelocity.angularvelocity = Vector3.new(0, VehicleSeat.TurnSpeed, 0)
- --local Direction = VehicleSeat.CFrame
- --local AngleX, AngleY, AngleZ = Direction:toEulerAnglesXYZ()
- local Guide = VehicleSeat.CFrame * CFrame.new(-1, 0, 0)
- BodyGyro.cframe = CFrame.new(VehicleSeat.Position, Vector3.new(Guide.X, VehicleSeat.CFrame.Y + (-Config.TiltFactor * (VehicleSeat.TurnSpeed/Config.MaxTurn)), Guide.Z))
- BodyVelocity.velocity = VehicleSeat.CFrame.lookVector * VehicleSeat.MaxSpeed
- wait(0.1)
- end
- end
- -- Variables --
- local Boat = script.Parent.Parent
- local VehicleSeat = script.Parent
- local Config = {
- TopSpeed = 55; -- How fast it can go. (In studs)
- TopSpeedReverse = 30; -- How fast is can go in reverse (In studs)
- MaxTurn =0.7; -- 1 = complete turn in 1 second 0.5 means complete turn (360) in 2 seconds.
- TurnSpeedAddition = 0.05;
- TurnStop = 0.05;
- TiltFactor = -0.02; -- Amount it tilts.
- ShipName = script.Parent.Parent.Name;
- }
- SetupBoat(Boat, VehicleSeat, Config)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement