#Car doesn't spawn from ServerStorage at runtime for some reason
1 messages · Page 1 of 1 (latest)
the first script is sometihng that autospawns and assigns cars
--Wait for 5 seconds before starting the script
task.wait(5)
local players = game:GetService("Players"):GetPlayers()
local carArray = {}
--Make this array because IDK if the roblox players array stays in the same order
local playersArray = {}
local car = game:GetService("ServerStorage"):WaitForChild("Car")
local function createCars()
--Spawn seats and assign each seat an attribute based on player's id
for i, player in ipairs(players) do
local playerCar = car:Clone()
local playerSeat = playerCar:FindFirstChildWhichIsA("VehicleSeat", true)
playerSeat:SetAttribute("OwnerID", player.UserId)
playerCar:PivotTo(CFrame.new(0, 5, -10 * i))
playerCar.Parent = workspace
table.insert(carArray, playerCar)
table.insert(playersArray, player)
end
end
local function sitPlayersInSeats()
for i, player in ipairs(players) do
local playerCar = carArray[i]
local playerSeat = playerCar:FindFirstChildWhichIsA("VehicleSeat", true)
if player.UserId == playerSeat:GetAttribute("OwnerID") then
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
hrp.CFrame = playerSeat.CFrame + Vector3.new(0, 2, 0)
task.wait(0.1)
humanoid.Sit = true
end
end
end
createCars()
sitPlayersInSeats()
and this one just locks the player's camera to the seats
--Script to lock player's camera to the OFFSET from the seat
local OFFSET = Vector3.new(0, 15, -15)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local player = Players.LocalPlayer
local camera = Workspace.CurrentCamera
local seat
repeat
for _, s in ipairs(Workspace:GetDescendants()) do
if s:IsA("VehicleSeat") and s:GetAttribute("OwnerID") == player.UserId then
seat = s
break
end
end
task.wait(0.1)
until seat
local function isPlayerSeated()
local humanoid = seat.Occupant
if not humanoid then
return false
end
local character = player.Character or player.CharacterAdded:Wait()
return humanoid.Parent == character
end
local function updateCamera()
camera.CameraType = Enum.CameraType.Scriptable
local seatCFrame = seat.CFrame
local cameraPosition = seatCFrame.Position + seatCFrame:VectorToWorldSpace(OFFSET)
camera.CFrame = CFrame.new(cameraPosition, seatCFrame.Position)
end
RunService.RenderStepped:Connect(function()
if isPlayerSeated() then
updateCamera()
else
if camera.CameraType ~= Enum.CameraType.Custom then
camera.CameraType = Enum.CameraType.Custom
end
end
end)
It prints car in the console when u debugged it
Is there a random space in the name of "Car"
Like " Car"
yes