local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local template = ServerStorage:WaitForChild("StuntModel")
local spawnPoint = workspace:WaitForChild("ScooterSpawn")
-- создаём событие управления
local event = ReplicatedStorage:FindFirstChild("ScooterControl")
if not event then
event = Instance.new("RemoteEvent")
event.Name = "ScooterControl"
event.Parent = ReplicatedStorage
end
-- создаём самокат
local scooter = template:Clone()
scooter.Name = "PlayableScooter"
for _, part in ipairs(scooter:GetDescendants()) do
if part:IsA("BasePart") then
part.Anchored = false
part.CanCollide = false
end
end
local chassis = Instance.new("Part")
chassis.Name = "Chassis"
chassis.Size = Vector3.new(2.5, 0.5, 3)
chassis.Transparency = 1
chassis.CanCollide = true
chassis.Anchored = false
chassis.CFrame = spawnPoint.CFrame
chassis.Parent = scooter
for _, part in ipairs(scooter:GetDescendants()) do
if part:IsA("BasePart") and part ~= chassis then
local weld = Instance.new("WeldConstraint")
weld.Part0 = chassis
weld.Part1 = part
weld.Parent = chassis
end
end
scooter.Parent = workspace
scooter:PivotTo(spawnPoint.CFrame)
-- место для игрока
local seat = Instance.new("VehicleSeat")
seat.Name = "RiderSeat"
seat.Size = Vector3.new(1, 0.3, 1)
seat.Transparency = 1
seat.CanCollide = false
seat.CFrame = chassis.CFrame * CFrame.new(0, 1, 0)
seat.Parent = scooter
local weld = Instance.new("WeldConstraint")
weld.Part0 = chassis
weld.Part1 = seat
weld.Parent = seat
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Встать на самокат"
prompt.ObjectText = "Самокат"
prompt.KeyboardKeyCode = Enum.KeyCode.E
prompt.MaxActivationDistance = 7
prompt.Parent = seat
prompt.Triggered:Connect(function(player)
if seat.Occupant then return end
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
seat:Sit(humanoid)
end
end)
-- движение
game:GetService("RunService").Heartbeat:Connect(function()
if not scooter.Parent or not seat.Occupant then return end
local throttle = seat.Throttle
local steer = seat.Steer
local direction = chassis.CFrame.LookVector * throttle * 25
chassis.AssemblyLinearVelocity = Vector3.new(
direction.X,
chassis.AssemblyLinearVelocity.Y,
direction.Z
)
chassis.AssemblyAngularVelocity = Vector3.new(0, -steer * 2.5, 0)
end)
-- освобождение самоката
event.OnServerEvent:Connect(function(player, action)
if action == "Exit" and seat.Occupant then
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid and seat.Occupant == humanoid then
humanoid.Sit = false
end
end
end)
print("ScooterSystem запущен")