Seat.Disabled not turning off?

Hello, I’ve been having a problem with this short script, the script errors when trying to make the player sit, but the problem is at Disabled = false because it doesn’t toggle the disabled property off, and when script tries to make the player sit, it fails… That is my guess at least.

Goal is to make a vehicle where you sit by clicking on the door handles.

I am not really into vehicles and such, so having a bit of a hard time figuring out what the reason might be or how I can fix it.

Here is the ServerScript

wait()

local driver = false
local seat = script.Parent.Value.Value

script.Parent.MouseClick:Connect(function(player)
	if not driver then
		driver = player.Character.Humanoid
		print(driver:GetFullName())  -- Tested, Output ends with ; Humanoid
		print(driver.ClassName)  -- Tested, Output is ; Humanoid
		print(seat:GetFullName())  -- Tested, Output ends with ; PassengerSeat
		print(seat.ClassName)  -- Tested, Output is ; Seat
		seat.Disabled = false -- Doesn't enable it back
		seat:Sit(driver) -- Gives error here because the seat is disabled,
						 -- exact error; "Unable to cast value to Object"
	end
end)


seat.Changed:Connect(function()
	if not seat.Occupant then
		seat.Disabled = true
		driver = false
	end
end)

Im not very sure, but i believe when you define driver as false, you make it a bool value… maybe try “nil” instead of false.

This must be a Object Value.

It is already an object value, it wouldn’t output Seat when I called for its ClassName otherwise

It is putting in the false as the value, not the humanoid… for the driver.

I called the print(driver:GetFullName()) and even ClassName, and the results are there, it outputs the Humanoid

Didn’t work, I don’t think it matters

I believe your issue lies here:

you have to get the player and character and humanoid first because this is what the error is saying, it is unable to cast a value of the driver to the seat object.

Its a server script, dont you have to define player then wait for the character and its humanoid child to load in?

The player is given by the function…

script.Parent.MouseClick:Connect(function(player)
	if not driver then
		driver = player.Character.Humanoid

and if a player can find a car and click its door handle, I am pretty sure their humanoid is loaded in.

Then make it like this with a local inside the function:

What do you mean by local inside the function?

a local variable inside of the function

Can you give me an example, I don’t think I understand?

Can you provide a screenshot of the hierarchy of the parts, so we can see where the clickdetector, the vehicle seat, the handles and the script are?

Here is the script and the ObjectValue with ClickDetector, ObjectValue is binded to the seat, which are all in workspace under a model
image_2022-05-22_062916064

Seat that is in a different location, and binded thanks to ObjectValue
image_2022-05-22_063126528

Im definitely confused… what then is:


Alright, lets give a lesson on scripts,

script, is by default used to tell the code themselves,
.Parent, tells the code to go to the parent object of the previous object (In this case script)
first .Value, in this case is the name of the ObjectValue we have,
second Value, we have is the Value property of the ObjectValue, because ClickDetector which is the parent, doesn’t have a ValueProperty, it doesn’t cause any problems to use the name of a property as the child of something that doesn’t have that property.

I’ll carry this topic to bugs category
Edit; nvm, can’t. I added bug as a tag instead

So when the player clicks the door handle they sit?
So why do you disable the seat when the player clicks?

seat.Disabled = false -- Doesn't enable it back

Then whenever the Seat Properties are changed you are checking to see if there isn’t a player in the seat, then making the seat Disabled?

seat.Changed:Connect(function()
	if not seat.Occupant then
		seat.Disabled = true
		driver = false
	end
end)

Isn’t that completely backwards?

seat.Disabled = false enables it, You aren’t toggling the seat on or off, you are toggling its disabled property on or off. The problem I have is that seat.Disabled = false doesn’t work, it doesn’t toggle it off and keeps it true

1 Like