Vehicle Owning Script

Adding onto this, you should DEFINETLY use names over display names

  1. People could literally just NOT have a display name and your whole code breaks
  2. you wont have to check if players have a display name
  3. if multiple people have the same display name, they’ll all be able to access the vehicle unless you have a hidden value for the name, or a different sanity check
  4. way easier
1 Like

I can just do:

if occ.DisplayName == nil then
	billboard.TextLabel.Text = occ.Parent.Name .. "'s Vehicle"
end

The script will change the stringvalue to the player’s ACTUAL username.

1 Like

Try using the script i sent above for handling occupant changes. The stringvalue being the player’s real username is fine, but you’ll have to check for the display name being " " not nil.

1 Like

I also put a despawner in the script (it works when player resets), but idk how to break the countdown when a new owner is the occupant

script.Parent.OwnIt.Occupant:GetPropertyChangedSignal("Value"):Connect(function()
	if script.Parent.OwnIt.Occupant.Value == "NoOccupant" then
		for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
			if billboard.Name == "DespawnGui" then
				billboard.Enabled = true
				for i = 80, 0, -1 do
					billboard.TextLabel.Text = "Despawning in: " .. i
					wait(1)
				end
				billboard.TextLabel:GetPropertyChangedSignal("Text"):Connect(function()
					if billboard.TextLabel.Text == "Despawning in: 1" then
						wait(1)
						script.Parent.Parent:Destroy()
					end
				end)
			end
		end
	elseif script.Parent.OwnIt.Occupant.Value == script.Parent.Occupant.Parent.Name then
		for _, billboard in pairs(script.Parent.Parent:GetDescendants()) do
			if billboard.Name == "DespawnGui" then
				billboard.Enabled = true
				billboard.TextLabel.Text = "Despawn timer starts when player resets"
			end
		end
	end
end)
1 Like

To help with your

you don’t need to check if the text changed to that, after the for loop ends it will do whatever is after that, as for the checks, this is gonna be unoptimal again, but inside the despawning for loop you can check if there’s an occupant

for i = 80, 0, -1 do
    if script.Parent.OwnIt.Occupant.Value == "NoOccupant" then return end

    billboard.TextLabel.Text = "Despawning in: " .. i
    wait(1)
end
script.Parent.Parent:Destroy()
1 Like

It doesn’t work. The timer won’t begin now.

I updated the checks, it was checking for if there was a script.Occupant.Value when it should check if the value wasnt equal to NoOccupant, the updated script should work for your system

The countdown still won’t begin with the changes.

i believe that you changed it to script.Parent.OwnIt, just check if that has an occupant instead of script.Occupant.Value

Even with script.Parent.OwnIt, it also does not begin.
EDIT: Still doesn’t begin when the Occupant variable is removed.
ANOTHER EDIT: ok ima just solve this in a another topic

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.