I have this script made by the new ai
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
-- Assuming there's a UI button named "SpawnCarButton" under StarterGui
local spawnCarButton = script.Parent:WaitForChild("SpawnCarButton")
-- Assuming cars are stored in ReplicatedStorage under a folder named "Cars"
local carsFolder = ReplicatedStorage:WaitForChild("Cars")
-- Function to clone and position the car in front of the player
local function spawnCarForPlayer(player)
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Get a random car model from the Cars folder
local cars = carsFolder:GetChildren()
local randomIndex = math.random(1, #cars)
local selectedCar = cars[randomIndex]:Clone()
-- Position the car in front of the player
local spawnPosition = humanoidRootPart.Position + (humanoidRootPart.CFrame.LookVector * 10)
selectedCar.PrimaryPart = selectedCar.DriveSeat
selectedCar:SetPrimaryPartCFrame(CFrame.new(spawnPosition))
-- Parent the car to the workspace
selectedCar.Parent = Workspace
wait(15)
end
-- Connect the button click event to the spawn function
spawnCarButton.MouseButton1Click:Connect(function()
local player = Players.LocalPlayer
spawnCarForPlayer(player)
end)
When i press the ui button, it DOES spawn the car in front of me, but it is floating and all functionality of it is broken, i can not get in the driver’s seat. No clue if the AI did something wrong as I wouldnt know any better. If anyone knows how to fix this that would be highly appreciated