Seat ClickDetection Script

I made this script but the detection max activation distance don’t change.

local SoundBase=script.Parent.Parent.BodyKit.SoundEscape
local DriverSeat=script.Parent.DriverSeat
local DriverHUD=script.Parent.DriverHUD
local PassengerSeat=script.Parent.PassengerSeat
local PassengerHUD=script.Parent.PassengerHUD
PassengerHUD.click.MouseClick:connect(function(plr)
if PassengerSeat.Occupant then
PassengerHUD.click.MaxActivationDistance=0
SoundBase.MetalDoorSlam:Play()return end --play sound if human in seat
local char=plr.Character
if not char then return end
local humanoid=char:FindFirstChildOfClass(“Humanoid”)
if not humanoid then return end
SoundBase.MetalDoorOpen:Play()
PassengerSeat:Sit(humanoid)
end)

DriverHUD.click.MouseClick:connect(function(plr)
if DriverSeat.Occupant then
DriverHUD.click.MaxActivationDistance=0
SoundBase.MetalDoorSlam:Play()return end
local char=plr.Character
if not char then return end
local humanoid=char:FindFirstChildOfClass(“Humanoid”)
if not humanoid then return end
SoundBase.MetalDoorOpen:Play()
DriverSeat:Sit(humanoid)
end)

if DriverSeat.Occupant then
wait()
DriverHUD.click.MaxActivationDistance=8
end

1 Like

It don’t change back to 8 distance, can someone help me? Thanks!

1 Like

The piece of code that sets it to 8 runs once at the start and the if statements condition isn’t met. After that, it doesn’t check again. Easily fixable if you just wrap it in a while loop.

can you give me an example?

thanks!

while true do
     wait()
     if DriverSeat.Occupant then
          DriverHUD.click.MaxActivationDistance=8
     end
end

Ignore the spacing, on mobile.

1 Like

Or he could just use the :GetPropertyChangedSignal(“Occupant”) because it’s more optimized than loops

2 Likes

damn, it is not working, can you show me in the script that I made??

1 Like

@szkiller_dev is suggesting that you take the part inside if DriverSeat.Occupant then ... end and instead of having an if/else statement there, you would wrap it with a signal/event connection to GetPropertyChangedSignal(“Occupant”).

1 Like

function Seat()
DriverHUD.click.MaxActivationDistance=8

DriverSeat:GetPropertyChangedSignal(“Occupant”):Connect(Seat)

make sure the “DriverSeat” variable is properly directed

1 Like

yay its my first time getting the solution for someone’s problem :smiley:

1 Like