Hello!! I have car despawn script but then car despawn I see this error
local car = script.Parent.Parent.Parent.Body.Mesh.Paint.Paint
local oncar = false
local seat = script.Parent
local timer = 0
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
oncar = true
else
oncar = false
end
end)
while true do
touching = false
if oncar == false then
if timer ~= 60 then
timer = timer + 1
else
if script.Parent.Parent.Parent then
if script.Parent.Parent.Parent.Name == "Basic" then
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local results = GetTouchingParts(car)
if touching == false then
script.Parent.Parent.Parent:Destroy()
timer = 0
else
timer = 0
end
end
end
end
else
timer = 0
end
wait(1)
end
local vehicle = script:FindFirstAncestorWhichIsA("Model")
local car = script:FindFirstAncestorWhichIsA("Model").Body.Mesh.Paint.Paint
local seat = script.Parent
local oncar = false
local timer = 0
local results = nil
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
oncar = true
elseif not seat.Occupant then
oncar = false
end
end)
while task.wait(1) do
touching = false
if not oncar then
if timer ~= 60 then
timer += 1
elseif timer == 60 then
if vehicle.Name == "Basic" then
results = car:GetTouchingParts()
if not touching then
vehicle:Destroy()
timer = 0
elseif touching then
timer = 0
end
end
end
elseif oncar then
timer = 0
end
print(table.concat(results, ", "))
end
I’m doubting this will work because the way you have referenced everything seems incredibly awkward.
local vehicle = script:FindFirstAncestorWhichIsA("Model")
local car = script:FindFirstAncestorWhichIsA("Model").Body.Mesh.Paint.Paint
local seat = script.Parent
local oncar = false
local timer = 0
local results = nil
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if seat.Occupant then
oncar = true
elseif not seat.Occupant then
oncar = false
end
end)
while task.wait(1) do
touching = false
if not oncar then
if timer ~= 60 then
timer += 1
elseif timer == 60 then
if vehicle.Name == "Basic" then
results = car:GetTouchingParts()
if not touching then
vehicle:Destroy()
timer = 0
elseif touching then
timer = 0
end
end
end
elseif oncar then
timer = 0
end
if results then
print(table.concat(results, ", "))
else
print("Nothing touched!")
end
end