Hello. I have this vehicle owning script.
However, the despawn countdown part broke in a roblox update:
script.Parent.OwnIt.Occupant:GetPropertyChangedSignal("Value"):Connect(function()
if script.Occupant.Value == "NoOccupant" then
for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
if billboard.Name == "DespawnGui" and billboard ~= nil then
billboard.Enabled = true
for i = 80, 0, -1 do
if script.Occupant.Value ~= "NoOccupant" then return end
billboard.TextLabel.Text = "Despawning in: " .. i
print(script.Parent.Parent.Name .. " is being despawned...")
wait(1)
end
script.Parent.Parent:Destroy()
print("Sucessfully despawned " .. script.Parent.Parent.Name)
else
wait(80)
script.Parent.Parent:Destroy()
print("Sucessfully despawned " .. script.Parent.Parent.Name)
end
end
elseif script.Occupant.Value ~= "NoOccupant`" then
for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
if billboard.Name == "DespawnGui" then
billboard.Enabled = false
billboard.TextLabel.Text = "Despawn timer starts when player resets"
end
end
end
end)
Also your script is saying script.Parent.OwnIt.Occupant,
script.Parent Is OwnIt, so that won’t work. suprised theres no errors.
Secondly, why would the string values “Occupant” property change, is there a script changing it? Did you mean to use the VehicleSeats “Occupied” property and not the string value?
Use the .Occupant value of the seat to check for people sitting. You can also remove the Occupant StringValue you have.
Code:
local Seat = script.Parent
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant then
for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
if billboard.Name == "DespawnGui" and billboard ~= nil then
billboard.Enabled = true
for i = 80, 0, -1 do
if script.Occupant.Value ~= "NoOccupant" then return end
billboard.TextLabel.Text = "Despawning in: " .. i
print(script.Parent.Parent.Name .. " is being despawned...")
task.wait(1)
end
script.Parent.Parent:Destroy()
print("Sucessfully despawned " .. script.Parent.Parent.Name)
else
task.wait(80)
script.Parent.Parent:Destroy()
print("Sucessfully despawned " .. script.Parent.Parent.Name)
end
end
else
for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
if billboard.Name == "DespawnGui" then
billboard.Enabled = false
billboard.TextLabel.Text = "Despawn timer starts when player resets"
end
end
end
end)
Here is the rest of the script, which sets those values.
script.Parent:GetPropertyChangedSignal("Occupant"):Connect(function()
if script.Parent.Occupant then
local occupant = script.Parent.Occupant
if script.Occupant.Value == "NoOccupant" or script.Occupant.Value == occupant.Parent.Name then
script.Occupant.Value = occupant.Parent.Name
for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
if billboard.Name == "OccupantGui" and billboard ~= nil then
if occupant.DisplayName == nil then
billboard.TextLabel.Text = occupant.Parent.Name .. "'s Vehicle"
else
billboard.TextLabel.Text = occupant.DisplayName .. "'s Vehicle"
end
end
end
local deathConnection
deathConnection = occupant.Died:Connect(function()
script.Occupant.Value = "NoOccupant"
deathConnection:Disconnect()
end )
else
print("Occupant is not owner")
wait(.1)
local sw = script.Parent:FindFirstChild("SeatWeld")
sw:Destroy()
end
else
script.Occupant:GetPropertyChangedSignal("Value"):Connect(function()
for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
if billboard.Name == "OccupantGui" and script.Occupant.Value == "NoOccupant" and billboard ~= nil then
billboard.TextLabel.Text = "Vacant Vehicle"
end
end
end)
end
end)