Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --// Made by remi
- -- Script located inside the car to give ownership.
- local physicsSevice = game:GetService("PhysicsService")
- local playerService = game:GetService("Players")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local serverStorage = game:GetService("ServerStorage")
- local control_remote = replicatedStorage.ControlRemote
- local wheel_template = serverStorage.Wheel
- local car = script.Parent
- local body = car.Body
- local seat = car.Seat
- local speed = car:GetAttribute("Speed")
- local vertical_speed = car:GetAttribute("VerticalSpeed")
- local turn_speed = car:GetAttribute("TurnSpeed")
- local torque = car:GetAttribute("Torque")
- local vertical_acceleration = car:GetAttribute("VerticalAcceleration")
- local acceleration = car:GetAttribute("Acceleration")
- local aesthethics = car.Aesthetics
- local constraints = body.Constraints
- local physics = car.Physics
- local occupant_changed = seat:GetPropertyChangedSignal("Occupant")
- local enter_prompt = seat.Enter
- local current_occupant = nil
- local function CharacterCanCollide(character)
- local collision_group = nil
- local massless = false
- if physicsSevice:CollisionGroupContainsPart("NonCollide", character.PrimaryPart) then
- collision_group = "Default"
- else
- collision_group = "NonCollide"
- massless = true
- end
- for _, part in pairs(character:GetChildren()) do
- if part:IsA("BasePart") then
- physicsSevice:SetPartCollisionGroup(part, collision_group)
- part.Massless = massless
- end
- end
- end
- local function OnPlayerLeave(player)
- local character = player.Character
- CharacterCanCollide(character)
- enter_prompt.Enabled = true
- control_remote:FireClient(player)
- body:SetNetworkOwnershipAuto()
- current_occupant = nil
- end
- local function OnPlayerEnter(player)
- if current_occupant then return end
- local character = player.Character
- local humanoid = character.Humanoid
- CharacterCanCollide(character)
- seat:Sit(humanoid)
- enter_prompt.Enabled = false
- control_remote:FireClient(player, "start", car, speed, turn_speed, torque, acceleration, vertical_speed, vertical_acceleration)
- body:SetNetworkOwner(player)
- current_occupant = player
- end
- local function Init()
- local wheels = physics.Wheels
- for _, physics_wheel in ipairs(wheels:GetChildren()) do
- local aesthethics_wheel = wheel_template:Clone()
- aesthethics_wheel.CFrame = physics_wheel.CFrame
- aesthethics_wheel.Size = physics_wheel.Size
- aesthethics_wheel.Parent = aesthethics
- local motor6d = Instance.new("Motor6D")
- motor6d.Part0 = physics_wheel
- motor6d.Part1 = aesthethics_wheel
- motor6d.Parent = physics_wheel
- end
- for _, constraint in ipairs(constraints:GetDescendants()) do
- if constraint:IsA("CylindricalConstraint") then
- constraint.MotorMaxTorque = torque
- end
- end
- end
- Init()
- enter_prompt.Triggered:Connect(OnPlayerEnter)
- occupant_changed:Connect(function()
- if seat.Occupant then return end
- if not current_occupant then return end
- OnPlayerLeave(current_occupant)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement