#my script wont make custom proximity prompt work on the car local script

1 messages · Page 1 of 1 (latest)

civic vale
#
local player = game.Players.LocalPlayer

local button = script.Parent
local carFolder = ReplicatedStorage:FindFirstChild("CarSpawnFolder")

button.MouseButton1Click:Connect(function()
    local character = player.Character or player.CharacterAdded:Wait()
    local rootPart = character:WaitForChild("HumanoidRootPart")

    -- Cleanup old car
    local oldCar = workspace:FindFirstChild(player.Name .. "_Car")
    if oldCar then oldCar:Destroy() end

    local carTemplate = carFolder and carFolder:FindFirstChild("Hondasion")

    if carTemplate then
        local newCar = carTemplate:Clone()
        newCar.Name = player.Name .. "_Car" 

        -- Anchor briefly to prevent falling through the map
        for _, part in pairs(newCar:GetDescendants()) do
            if part:IsA("BasePart") then part.Anchored = true end
        end

        newCar.Parent = workspace
        newCar:SetPrimaryPartCFrame(rootPart.CFrame * CFrame.new(0, 8, -15))

        -- FIX: Tell every script inside the car "This is your car"
        for _, desc in pairs(newCar:GetDescendants()) do
            if desc:IsA("LocalScript") or desc:IsA("Script") then
                local carVal = desc:FindFirstChild("CarValue")
                if carVal then carVal.Value = newCar end

                desc.Disabled = true
                desc.Disabled = false
            end
        end

        task.wait(0.5)
        for _, part in pairs(newCar:GetDescendants()) do
            if part:IsA("BasePart") then part.Anchored = false end
        end
    end
end)```