Using Bool Value to Set Owned Vehicle Stolen Status

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m wanting to use a bool value inside of vehicle’s DriveSeat that when someone who IS NOT the owner of the vehicle enters the vehicle, the bool value is automatically swapped to “true”. It is to set a vehicle’s stolen status to true. From there, I’ll be also scripting it to place a warrant out for the arrest of the player who stole that vehicle, but that’s something for later :slight_smile:

  2. What is the issue? Include screenshots / videos if possible!
    I’ve tried searching around and found some helpful articles, but for my exact situation I haven’t been able to locate anyone with similar issues. Essentially, the value doesn’t change when a non-owner gets into the vehicle. The value stays false.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Here is a portion of the script I’m using in my PlayerData server script that sets the owner of the vehicle etc. Note that all attributes work fine, none of that is the issue, the issue is simply the bool value not changing.

local carModel = car:clone()
		carModel.PrimaryPart = carModel:FindFirstChildOfClass("VehicleSeat")
		carModel:SetPrimaryPartCFrame(carSpawnTiles[carFolder.Name]:GetChildren()[carSpawnIndex + 1].CFrame)
		carModel.Parent = workspace.SpawnedCars
		carModel.Body.LicensePlate.Rear.SGUI.Identifier.Text = plr.ID.Value
		carModel:SetAttribute("id", plr.ID.Value)
		carModel:SetAttribute("type", carFolder.Name)
		carModel:SetAttribute("owner", plr.Name)
		local stolen ="BoolValue")
		stolen.Name = "Stolen"
		stolen.Value = false
		stolen.Parent = carModel.DriveSeat

Now here is a server script placed inside of the vehicle’s DriveSeat

local stolenValue = script.Parent.Stolen.Value
local seat = script.Parent.Parent
local carOwner = script.Parent.Parent:GetAttribute("owner")

	if tostring(seat.Occupant) == "Humanoid" then
		local CurrentCharacterOccupyingSeat = seat.Occupant.Parent
		if CurrentCharacterOccupyingSeat.Name == carOwner then
			stolenValue = false
			stolenValue = true

If anyone has any idea on a correct path I could go to get this working, you’d have my utmost gratitude!
Thank you in advanced!

1 Like

This variable declaration is referencing the current value of your BoolValue, so stoleValue is a boolean with no relation to the BoolValue.

What you want to do instead is put the BoolValue itself in a variable, and then change it’s value through that.

local stolen = script.Parent.Stole
-- and then later
stolen.Value = true

Although, I would recommend use custom Attributes for this instead as they are meant to be a replacement for using Value Instances like this.

1 Like

Ohhh! I see let me try that.
And okay I see, I used a value instead of an attribute for the stolen status because I wasn’t sure how to exactly change the value of an attribute (I wasn’t sure if it would be more difficult to script rather than using a value)

Attributes aren’t more difficult to use. They just have a different syntax. I didn’t explain that because I saw you using attributes in your code.

You can use Instance:SetAttribute("attr", value) to change the value stored (this goes for creating an attribute that doesn’t exist or updating an existing attribute).

And then you can reference the attribute’s value with local value = Instance:GetAttribute("attr")