Sitting makes the player not be available to walk ¿?

Hello, I am working on a car system but ¿?
When player leaves, it can’t walk for some reason
video;

as you can see, walkspee is set to 16, and still can’t move!
No clue why.

This is the code that gives the local script to player;

DriveSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local occupant = DriveSeat.Occupant
	if (occupant) then
		local Player = game.Players:GetPlayerFromCharacter(occupant.Parent)
		if (Player) then
			lastPlayer = Player
			if (Player.PlayerGui:FindFirstChild("carLocal")) then
				return
			end
			local scriptt =  game.ReplicatedStorage.Events.CarSystem.carLocal:Clone()
			scriptt.Parent = Player.PlayerGui
			scriptt.Car.Value = car
			scriptt.Disabled = false
			ConnectEvents(scriptt)
			for i,v in pairs(car:GetDescendants()) do
				if v:IsA("BasePart") then
					v:SetNetworkOwner(Player)
				end
			end
		end
	else -- no occupant
		if (lastPlayer) then
			lastPlayer.PlayerGui.carLocal:Destroy()
		end
		game.ReplicatedStorage.Events.CarSystem.CloseCarUI:FireClient(lastPlayer)
		for i,v in pairs(car:GetDescendants()) do
			if v:IsA("BasePart") then
				v:SetNetworkOwner(nil)
			end
		end
		car.Chassis.VehicleSeat.EngineStart:Stop()
		car.Chassis.VehicleSeat.Engine:Stop()

		
	end
end)

image

1 Like

It’s probably the local script thats causing the issue. I believe the local script uses the contextual action service to bind the wasd keys to driving the car while unbinding the original movement keys so you should check there.

3 Likes

oh yes, I forgot context action services makes this.
Is there a way to disable this?
Or I must unbind actions

1 Like

Yeah I believe its something like this which is what I did for my controller before in a local script. Just unbind what you binded before when the humanoid is unseated.

function onSeated(isSeated, seat)
	if isSeated then
		print("I'm now sitting on: " .. seat.Name .. "!")
		ContextActionService:BindAction("Move", onMove, false, FORWARD_KEY)
		ContextActionService:BindAction("MoveBack", moveBack, false, BACKWARDS_KEY)
		ContextActionService:BindAction("Right", rotateRight, false, RIGHT_KEY)
		ContextActionService:BindAction("Left", rotateLeft, false, LEFT_KEY)
	else
		print("I'm not sitting on anything")
		ContextActionService:UnbindAction("Move")
		ContextActionService:UnbindAction("MoveBack")
		ContextActionService:UnbindAction("Right")
		ContextActionService:UnbindAction("Left")
	end
end

--event for when player sits or not
humanoid.Seated:Connect(onSeated)

2 Likes

Is there a way to know if a local script is getting destroyed before it destroys?
To unbind actions :smiley:
Tried this but doesn’t prints uh oh, so doesnt fires D:

script.AncestryChanged:Connect(function()
	Events.CarEnter:Fire(false)
	CAS:UnbindAction("light")
	CAS:UnbindAction("horn")
	CAS:UnbindAction("gear")
	CAS:UnbindAction("parking brake")
	CAS:UnbindAction("gear")
	CAS:UnbindAction("move")
	print('uh oh')
end)
1 Like

Hmm, maybe in a seperate local script given to all clients detect locally when the player leaves the car using the humanoid seated event like above.

humanoid.Seated:Connect(onSeated)

Then just use unbind all actions to reset everything.

ContextActionService:UnbindAllActions()
1 Like

Would ContextActionService:UnbindAllActions() unbind EVERY action like movement? Correct me if I’m wrong I’m just unsure.

1 Like

Well, yeah actually according to my research, didn’t think about that good catch

Yeah just do the manual unbinding like what’s been written before. The good thing about this in the scenario is that it doesn’t error so you can just unbind the moment you leave the seat.

	CAS:UnbindAction("light")
	CAS:UnbindAction("horn")

1 Like