Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with my car selection system?

Asked by 2 years ago
Edited 2 years ago

so I'm making a car game and i need a feature so players can spawn cars so I want a menu with all the list of cars and once they click it displays a preview and once they hit spawn it spawns and they get teleported to it here is the current code:

wait()
local Items = game.ReplicatedStorage.Karts
local Platform = game.ReplicatedStorage.Platform
local FirstItem = game.ReplicatedStorage.Karts.Kart
local Camera = workspace.CurrentCamera
local sample = script.Parent.ScrollingFrame.Sample:Clone()
local Item = nil

if not Camera:FindFirstChild("Platform") then
    local Cloned = Platform:Clone()
    Cloned.Parent = Camera
end

if not Camera:FindFirstChild("PrevItem") then
    local Cloned = FirstItem:Clone()
    Cloned.Parent = Camera
    Cloned:MakeJoints()
    Item = FirstItem
    Cloned:SetPrimaryPartCFrame(Camera:FindFirstChild("Platform").TheCFrame.CFrame)
    Cloned.Name = "PrevItem"
end

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = script.CameraVal.Value

for i,v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
    if v.Name ~= "Sample" then
        v:Destroy()
    end
end

for i,v in pairs(Items:GetChildren()) do
    local a = sample:Clone()
    a.Parent = script.Parent.ScrollingFrame
    a.Position = UDim2.new(0,0,0,25*(i-1))
    a.Name = v.Name
    a.Text = v.Name
    a.Visible = true
end

for i,v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
    v.MouseButton1Click:connect(function()
        if Camera:FindFirstChild("PrevItem") then
            Camera.PrevItem:Destroy()
            local realitem = game.ReplicatedStorage.Karts:FindFirstChild(v.Name)
            if realitem then
                local Cloned = realitem:Clone()
                Cloned.Parent = Camera
                Cloned:MakeJoints()
                Cloned:SetPrimaryPartCFrame(Camera:FindFirstChild("Platform").TheCFrame.CFrame)
                Cloned.Name = "PrevItem"
                Item = realitem         
            end
        end
    end)
end

script.Parent.Play.MouseButton1Click:connect(function()
    if Item ~= nil then
        local Cloned = Item:Clone()
        Cloned.Parent = Camera
        Cloned:MakeJoints()
        Cloned:SetPrimaryPartCFrame(workspace.sPawn.CFrame)
        Cloned.Name = "PrevItem"
        game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = Cloned.PrimaryPart.CFrame
        Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
        Camera.CameraType = Enum.CameraType.Custom
    end
end)

but once I add a new car it doesn't spawn on the platform and breaks the code

0
Do you have any errors in the console? bbissell 346 — 2y

Answer this question