Values not getting reset

Hi, I am developing a boat and have also finished it however I have this bug where if I leave the boat still holding keys that make it move(w,a,s,d) then is will continue to move even tho I remove the script that lets the player control the boat and I removed it permissions, so I tried to reset the values (vector force and the motor thing inside of cylindrical constraint) but it still wont reset I even made it so that the script that resets the values would have to wait for the script that is sent to the player but that just errors because I already deleted it before I check. any help would be appreciated

robloxapp-20210329-1931303.wmv (6.0

local VehicleSeat = script.Parent
local _lastPlayer

VehicleSeat.Changed:Connect(function(prop)
	if prop == "Occupant" then
		local humanoid = VehicleSeat.Occupant
		if humanoid then
			local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
			if player then
				VehicleSeat:SetNetworkOwner(player)
				_lastPlayer = player.Name
				script.Parent.Parent.Name = player.Name.." Boat"
				
				local playerScript = script.Parent.BoatScript:Clone()
				playerScript.Parent = game.Players[tostring(player.Name)].Backpack
				
			end
		else
			if game.Players[_lastPlayer].Backpack.BoatScript then
				game.Players[_lastPlayer].Backpack.BoatScript:Destroy()
			end			
			script.Parent.Parent.Tail.CylindricalConstraint.TargetAngle = 0 -- not working note sure why
			script.Parent.Parent.Tail.VectorForce.Force = Vector3.new(0,0,0)-- not working not sure why
			print("should be reset?")
			
			VehicleSeat:SetNetworkOwnershipAuto()
		end
	end
end)

local script

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local _boat = game.Workspace[script.Parent.Parent.Name.." Boat"]

local _forward
local _backword
local _left
local _right

UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then -- check if input was from keyboard
		local value = inputObject.KeyCode -- the value of the enum
		if value == Enum.KeyCode.W then
			_forward = true
		end

		if value == Enum.KeyCode.S then
			_backword = true
		end
		
		if value == Enum.KeyCode.A then
			_left = true
		end
		
		if value == Enum.KeyCode.D then
			_right = true
		end
		
	end
end)

UserInputService.InputEnded:Connect(function(inputObject)
	if inputObject.UserInputType == Enum.UserInputType.Keyboard then -- check if input was from keyboard
		local value = inputObject.KeyCode -- the value of the enum
		if value == Enum.KeyCode.W then
			_forward = false
		end
		
		if value == Enum.KeyCode.S then
			_backword = false
		end
		
		if value == Enum.KeyCode.A then
			_left = false
		end
		
		if value == Enum.KeyCode.D then
			_right = false
		end
	end
end)

RunService.Stepped:Connect(function()
	if _forward == true then
		_boat.Tail.VectorForce.Force = Vector3.new(-5000,_boat.Tail.VectorForce.Force.Y,_boat.Tail.VectorForce.Force.Z)
	elseif _backword == true then
		_boat.Tail.VectorForce.Force = Vector3.new(5000,_boat.Tail.VectorForce.Force.Y,_boat.Tail.VectorForce.Force.Z)
	else
		_boat.Tail.VectorForce.Force = Vector3.new(0,_boat.Tail.VectorForce.Force.Y,_boat.Tail.VectorForce.Force.Z)
	end

	if _left == true then
		_boat.Tail.CylindricalConstraint.TargetAngle = 10
	elseif _right == true then
		_boat.Tail.CylindricalConstraint.TargetAngle = -10
	else
		_boat.Tail.CylindricalConstraint.TargetAngle = 0
	end
end)

Exlporer
MB)

I can think of 2 things:

  • Since the InputEnded isn’t detecting any keys removed for the keyboard (Cause you’re still holding them in the process), it’s resulting as the part still moving

    • You could implement a check to detect when the player jumps out of the seat in the LocalScript, then change all the values to false on there perhaps?

Or

  • Could you try printing what each variable gives you every time Stepped is called?

So in the sever script it checks if there are any change if so a function fires when the players sits and un sits where in sits I reset the values. But it doesn’t work

Could you try adding this in-between the InputEnded & Stepped Events?

local Seat = _boat.Seat

Seat.Changed:Connect(function(prop)
	if prop == "Occupant" then
		local humanoid = Seat.Occupant
		if humanoid then
			print("I have no idea what I'm doing at this point")
        else
           _forward = false
           _backword = false
           _left = false
           _right = false
        end
    end
end)

I think I understand what u mean I will try implement this in my local script thanks for the idea