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)
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?
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.
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